Token does not work for me with Automatic Nodetitles even for the most simple case, when i just write [nid] in 'Pattern for the tittle' - it return no title. When i add some text, it returns text but no token value from node variable. I use custom node type created with CCK. I am using latest versions of both - Token 5.x-1.9 and Automatic Nodetitles 5.x-1.1 (downloaded today) and Drupal 5.3. I am completely lost - what I am doing wrong? Thank you very much.

Comments

grah’s picture

some of the tokens won't work during node creation. such as [nid] just because the node hasn't been created, so there is no nid.

[user-id] and such work though. :/

fago’s picture

Status: Active » Fixed
Anonymous’s picture

Status: Fixed » Closed (fixed)

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

alanburke’s picture

Category: support » bug
Status: Closed (fixed) » Active

Sorry to open a closed issue, but I'm not sure that was the correct end to the issue.

I now understand that while many tokens as supplied by the token module will work, some will not.

Eg Nid is not available, nor is the taxomony term
[term] Name of top taxonomy term.

So there are 3 possible solutions:

1. Change the order of when Automatic Nodetitles does its work, such that those tokens become available for it to use
[Probably very difficult]

2. Reduce the set of token displayed as available for use. EG Remove [nid], [term] form the list of tokens.
Again, this is problematic, as any module can supply a token, how would Automatic Nodetitles which ones would work, and which would not.

3. Document the issue.
The readme file is already excellent, so perhaps just adding a line that some tokens may not be available would be suitable.

Thanks for the great work,
Regards
Alan

alanburke’s picture

To Clarify
These tokens are unavailable on Node creation

They become available on node editing.

Regards
Alan

fago’s picture

Right, this should be mentioned in the README.

So a patch for 3) would be welcome.

fago’s picture

Title: token not working » some tokens don't work when initially creating a node
patchak’s picture

It's weird cause using some fields like content taxonomy or other cck fields, or even the original node submission do work, so why is it that some fields work, but not some others ?? Would be nice if we could use term name and such in the auto node title, otherwise it's a little difficult to use...

bengtan’s picture

Hi,

I can explain why auto node title doesn't work for nid, but this may not explain why all other token values are not yet available during node creation.

Essentially, nid is not available during node creation because of the way Drupal core 5.x is written. There is no module hook between the time when a to-be-created node is assigned it's nid and the time when the node is actually saved to the database.

These two events occur in the same Drupal function (it's node_save() if you're curious).

Auto node title works by hooking into a node_submit hook, which is invoked before the node_save. At this point, the new node's nid has not been assigned yet.

asak’s picture

Is there any token one could use to generate a unique title for every node?

If i could just get a num which i would be certain that it's unique i could play with the rest of the available tokens to construct a nice unique title..

kenorb’s picture

Component: Miscellaneous » Code

Probably I've similar problem in Drupal 6.x.
When I'm creating node (using user_register form with content_profile module), the title is not generated.
Followed callback is not call after submit:

$form['#submit'][] = 'auto_nodetitle_node_form_submit';

It's the same issue?
How to fix that?

fago’s picture

@kenorb: no, it's another issue see http://drupal.org/node/325280

mariusooms’s picture

Title: some tokens don't work when initially creating a node » many tokens don't work when initially creating a node

This is still an issue somehow. I don't understand why tokens that don't work are listed as an option, e.g none of the datestamp tokens work either. Even updating path auto afterward doesn't seem to work. Is there a working list of tokens that are available at node creation?

Regards,

Marius

mariusooms’s picture

Title: many tokens don't work when initially creating a node » some tokens don't work when initially creating a node
Version: 5.x-1.1 » 6.x-1.x-dev

Apologies....I mistakenly used wrong syntaxing...ahem...date tokens work fine. Still wish top term could be parsed at node creation.

Regards,

Marius

alexfisher’s picture

Ditto.

stormsweeper’s picture

Status: Active » Closed (works as designed)

This is not really an automatic node titles issue, but a factor of how Token works. You can use PHP in the field (it's pretty much the same as grabbing the term for a theme function), which works better to boot.

Encarte’s picture

subscribing

kenorb’s picture

You may try solution by defining following hook in your custom module:

/**
 * Implementation of hook_nodeapi().
 */
function hook_nodeapi(&$node, $op) {  
      switch ($op) {
          case 'alter':                           
              $node->title =  token_replace_multiple($node->title);
          break;        
          }    
}

I haven't tested it, so you may try to change 'alter' to something like 'presave' and can add additional condition to apply token only for specified content types.

squarecandy’s picture

subscribe... would like to see this available too...

drseussofporn’s picture

I just thought I would throw in a quick workaround to the problem. Using Rules you can apply the title after the node has been created when such items as nid are available.

Ace Cooper’s picture

To drseussofporn: thank you for the wonderful idea!

I have created a Triggered Rule for the event "After saving new content" with the token [node:nid].

It works like a charm, no more overlapping node titles and no more database queries for Automatic Nodetitles. Woohoo, tnx!

johnhanley’s picture

@kenorb, I ran into this problem today. That is, missing token values when manually creating a node via node_save. Your hook_nodeapi workaround using the presave operation did the trick nicely, thanks!

John