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
Comment #1
itangalo commentedCool function!
I'd like to have it work only on single nodes, though, and then Rules' loops can be used for lists. Makes sense?
Comment #2
derhasi commentedI 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 usedauto_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 ;)
Comment #3
itangalo commentedSuper-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.