I have made two actions that update the Automatic Nodetitle for nodes.

The function names, labels and descriptions maybe need to be changed but I can not figure out any good ones right now.

// in function rb_misc_rules_action_info() {
  if (module_exists('auto_nodetitle')) {
    $actions['rb_misc_action_update_auto_nodetitle_for_node'] = array(
      'label' => t('Update title for a node'),
      'parameter' => array(
        'node' => array(
          'type' => 'node',
          'label' => t('Node to update'),
          'description' => t('Choose with node to update the automatic nodetitle.'),
        ),
      ),
      'group' => t('Rules Bonus: Miscellaneous'),
    );
    $actions['rb_misc_action_update_auto_nodetitle_for_nodes'] = array(
      'label' => t('Update title for list of nodes'),
      'parameter' => array(
        'node_list' => array(
          'type' => 'list<node>',
          'label' => t('List of nodes to update'),
          'description' => t('A list with nodes that should update the automatic nodetitle.'),
        ),
      ),
      'group' => t('Rules Bonus: Miscellaneous'),
    );
  }

// ---

/**
 * The 'rb_misc_action_update_auto_nodetitle_for_node' action.
 */
function rb_misc_action_update_auto_nodetitle_for_node($node) {
  auto_nodetitle_operations_update(array($node->nid));
}

/**
 * The 'rb_misc_action_update_auto_nodetitle_for_nodes' action.
 */
function rb_misc_action_update_auto_nodetitle_for_nodes($node_list) {
  $nodes = array();
  foreach ($node_list as $node) {
    $nodes[] = $node->nid;
  }
  auto_nodetitle_operations_update($nodes);
}

Comments

itangalo’s picture

Status: Needs review » Needs work

Cool function!
I'd like to have it work only on single nodes, though, and then Rules' loops can be used for lists. Makes sense?

derhasi’s picture

Status: Needs work » Needs review
StatusFileSize
new2 KB

I allready had a similar functionality prepared in a custom module, so I build a patch out of it...

* added a condition for the auto_nodetitle_is_needed()
* did not use the auto_nodetitle_operations_update() as this only works with nids (used node_load() itself) and not the node object, directly used auto_nodetitle_set_title() instead. node_load() can be achieved by rules anyway.

Thx, Scyther, for initially posting that idea.

Patch is attached and needs review ;)

itangalo’s picture

Status: Needs review » Fixed

Super-clean patch! Now committed.
Thanks to derhasi and Scyther for working on this.

PS: I posted an issue in Automatic Nodetitles about implementing this – see #408936: Rules integration with Automatic Node Titles.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.