Here is the simple example how to create custom node token in Drupal 7.
Lets say you want to crete a custom node token that will return a first letter of the node title.
So at the first step you need to declare your node token using hook_token_info:
function MYMODULE_token_info() { $info['tokens']['node']['title_first_letter'] = array( 'name' => t('Title first letter'), 'description' => t('Generates first letter of node title') ); return $info; }
Then you need to create a processing of that token:
function slideaway_currency_tokens($type, $tokens, array $data = array(), array $options = array()) { $replacements = array(); if ($type == 'node' && !empty($data['node'])) { $node = $data['node']; foreach ($tokens as $name => $original) { switch ($name) { case 'title_first_letter': $replacements[$original] = substr($node->title, 0, 1); // get first letter of the title here break; } } } return $replacements; }
Don't forget to flush the cache to update token register.
That's it: go to the token list and it should be there!

×
Comments
How can I make it work with panels_everywhere?
Was Ist Viagra Wikipedia Cialis In Farmacia Prezzo Canada Pharmacy Sells Levitra cialis 5 mg Cialis Seguro Red Viagra
Add new comment