Generat title AFTER the node is created
Stefan Vaduva - November 12, 2007 - 08:23
| Project: | Automatic Nodetitles |
| Version: | 5.x-1.1 |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | active |
Jump to:
Description
Hello,
I would like to be able to use this the node id in the title generated by this module and I'm wondering if there is any way to generate the title after the node is saved and the nid is generated.
Thank you!

#1
for most cases, the way it works suffices and performs better. So I won't change this.
However, if you want to do that, I'd suggest to write a simple "set the node title" action for workflow-ng (as ANT workflow-ng integration), which would allow you to do this.
#2
Interesting.. I didn't know about the workflow-ng module. Thank you very much! I'll try it and then I'll post here the solution if it works.
#3
One question regarding ANT and workflow: how can I see the ANT action in workflow?
#4
there is no such action yet. This was just an implementation idea.
#5
Fago, I didn't manage to solve the problem with the workflow-ng module so I've modified your module like this:
function auto_nodetitle_nodeapi(&$node, $op, $form = NULL, $a4 = NULL) {
if ($op == 'insert' || $op == 'validate') { //added the insert operation
if ((auto_nodetitle_get_setting($node->type) == AUTO_NODETITLE_ENABLED) || ((auto_nodetitle_get_setting($node->type) == AUTO_NODETITLE_OPTIONAL) && empty($node->title))) {
/*
* Sets the node title.
* We need to do this on validation because of two points:
* It's early engouh to have node previews working and
* it's late enough as CCK has already gone through the 'process form values' step
*
* As changes to $node are not persistent during validation, we use form_set_value()!
*/
auto_nodetitle_set_title($node);
//replace {nodeid} with the actual id of the node
$tmptile = $node->title;
$tmptile = str_replace('{nodeid}', $node->nid, $tmptile);
$node->title = $tmptile;
if($op == 'insert')
$mynode = node_save($node);
else
form_set_value($form['title'], $node->title);
}
}
}
So, if there is {nodeid} in the title, this is replaced by the actual id of the node. Do you think is safe for me to use your module modified like this?
#6
There's a simple workaround using the Rules (or Workflow-ng) module
See http://drupal.org/node/360359#comment-1460918