Token Starter: how to add a [tnid] token?
GN - July 28, 2009 - 12:40
| Project: | Token |
| Version: | 6.x-1.12 |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | active |
Jump to:
Description
It is very nice that the new Token Starter submodule makes it easier to add your own tokens.
To synchronize the URL's of the original node and its translations for a multilingual site, I'm trying to add a [tnid] token (tnid is the original node's nid for all translated nodes) and use it in pathauto (e.g. by setting URL's to 'languageprefix/contenttype/[tnid]').
I'm adding to the tokenSTARTER_token_list function the following string:
// Node tokens here.
$tokens['node']['tnid'] = t("Common nid for a set of translations.");and another string to the tokenSTARTER_token_values function:
// Node tokens here.
$values['tnid'] = $node->tnid;Now the new [tnid] token is visible in the list, but it does not seem to get the value.
Am I doing anything wrong here? 'tnid' values are kept in the 'node' table; should I use a more complicated expression to get the values from there?
Thank you!

#1
I think the problem is that if you don't have created a second transaltion $node->tnid is empty.
So i think
<?php$values['tnid'] = $node->tnid ? $node->tnid : $node->nid;
?>
#2
Thank you for the suggestion Daniel, but it does not work.
It occurred to me, too, that tnid may be not available yet when you are creating a new translation, but this token does not work even when you save the new node and then reopen it for editing.
#3
Hi,
did you manage to create a tnid token?
I need the same thing.
Thank you