You may have missed the implementation of hook_token_list . Providing a new token is a two-step process:
- Add a
hook_token_list to declare the tokens you are about to provide. It will be just the name of the tokens, as well as a brief explanation and information about what types of objects the tokens will use (for example, node, user, taxonomy, ...) hook_token_value to actually create token content. This will be triggered when the tokens must be replaced by the contents on which they should stand.
Since you just want to provide an alternative version of the header token already provided by the token module, it is probably best to simply copy the corresponding parts from token_node.inc, trim it to the appropriate cases, and adjust it for use in another module:
function yourModule_token_list($type = 'all') { if ($type == 'node' || $type == 'all') { $tokens['node']['yourModule-title'] = t('Node title (customized version by yourModule)'); return $tokens; } }
It just says that yourModule provides a token for node objects named yourModule-title along with a brief description. The main work is done in another hook:
function yourModule_token_values($type, $object = NULL, $options = array()) { $values = array(); switch ($type) { case 'node': $node = $object;
This will be called whenever tokens are needed for node objects, and the node question is passed as a parameter to $object (for a user token, $type will be a “user” and $object will be a user object, etc. for other types). What he does is create an array of values defined by the name of the token, replacing this token as the value. The source code from token_node.inc just launches the header through check_plain() , so this will be the place to insert your own logic.
source share