I've configured the node title to include the creation date using tokens like so:

[yyyy]-[mm]-[dd]

But it doesn’t display the node’s creation date; it displays “1969-12-31” (which undoubtedly is the UNIX epoch converted to my local timezone.)

This happens when initially creating the node. If I later update the node, the title will then show the creation date.

Comments

guardian’s picture

this is because node tokens are not available at creation time

when you're creating the node, the node is not in the database yet so tokens like [nid], [vocab], [term] or anything related to creation date cannot be used.

maybe one option could be:

  • at creation/edit time, provide dummy token replacements
  • alter auto_nodetitle module so that it hooks insertion (using hook_nodeapi) and replace the tokens with their final replacement

however, i'm afraid this would require modifications to both the token and auto_nodetitle modules.

fago’s picture

you could try combining php code with tokens and so create replacements, e.g.

$nid = "[nid]";
if (!$nid)
....

codewatson’s picture

this is because node tokens are not available at creation time

I'm not so sure thats true, i'm running into this only when a node is submitted by a user that only has the "create" permission and the node is set to be unpublished by default. If i submit the same type of node as the super user, it pulls the correct time in. However, with both user types the nid comes up blank until it is published, any reason for that?

codewatson’s picture

when you're creating the node, the node is not in the database yet so tokens like [nid], [vocab], [term] or anything related to creation date cannot be used.

Oy i'm blind, ignore the part about the missing nid...., still make my case for the time though...

codewatson’s picture

After playing around with permissions, i figured out that if the user has the "administer nodes" permission when they create a node, the date is correct, without that permission, the date is set back to the default. Only reason i can see why this would be is if the creation time is for some reason hidden in the form with that permission, and not without it?

guardian’s picture

this issue is being discussed here: http://drupal.org/node/137669

somehow i agree with eaton in the way that what's given to token by auto_nodetitle is not a node.

however, it does not seem straightforward at all to have token replacement happen after taxonomy_nodeapi with $op='insert' has saved the node.

fago’s picture

Status: Active » Closed (works as designed)

hm, yes. autonodetitle just takes the node object from hook nodeapi op validate - however the problem is that the node object looks different from time to time, so e.g. the taxonomy data structure is different from a "fresh loaded" node and newly created and not yet saved node. Imho best this problems would be tackled in the modules itself like taxonomy...

Token could also provide a workaround for it though. However I see nothing that I could do with autonodetitle, so I set this to by design.