drupal 7: how to create custom node token

Posted by admin on Sat, 11/11/2017 - 07:54

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!

Tags: 
×

Hey! Don't miss a new cool stuff!

Comments

pvasili (not verified)

How can I make it work with panels_everywhere?

enetibliole (not verified)

vegas slots online vegas slots online casino real money online casino gambling

enetibliole (not verified)

vegas slots online vegas slots online casino real money online casino gambling

enetibliole (not verified)

vegas slots online vegas slots online casino real money online casino gambling

enetibliole (not verified)

no deposit casino http://onlinecasinogamespcx.com/ - casino blackjack online casino real money slots for real money casino play

enetibliole (not verified)

online casino gambling http://onlinecasinogamespcx.com/ - slot games cashman casino slots casino bonus codes no deposit casino

enetibliole (not verified)

online casino gambling http://onlinecasinogamespcx.com/ - slot games cashman casino slots casino bonus codes no deposit casino

enetibliole (not verified)

casino online slots http://onlinecasinogamespcx.com/ online casinos casino play play casino

inticleni (not verified)

free slots games casino online slots free online slots

enetibliole (not verified)

http://onlinecasinogamespcx.com/ online gambling play slots online play slots online free casino

inticleni (not verified)

big fish casino slots free slots free online casino bonus http://onlinecasinosw.com/ - best online casino

enetibliole (not verified)

slots free http://onlinecasinogamespcx.com/ best online casinos slots online vegas casino slots

enetibliole (not verified)

slots free http://onlinecasinogamespcx.com/ best online casinos slots online vegas casino slots

inticleni (not verified)

http://onlinecasinosw.com/ casino play play slots online gold fish casino slots online slot games

inticleni (not verified)

http://onlinecasinosw.com/ casino play play slots online gold fish casino slots online slot games

enetibliole (not verified)

casino play online gambling free online slots

enetibliole (not verified)

casino play online gambling free online slots

Eohhnn k (not verified)
inticleni (not verified)

free casino slot games casino blackjack casino online slots free online slots http://onlinecasinosw.com/ - cashman casino slots

enetibliole (not verified)

play casino http://onlinecasinogamespcx.com/ - slots free casino blackjack free online slots

enetibliole (not verified)

play casino http://onlinecasinogamespcx.com/ - slots free casino blackjack free online slots

inticleni (not verified)

online casino gambling play online casino casino online slots casino bonus codes

enetibliole (not verified)

play casino http://onlinecasinogamespcx.com/ - slots free casino blackjack free online slots

enetibliole (not verified)

play casino http://onlinecasinogamespcx.com/ - slots free casino blackjack free online slots

inticleni (not verified)

casino game no deposit casino free casino slot games play online casino http://onlinecasinosw.com/ - vegas slots online

enetibliole (not verified)

casino play http://onlinecasinogamespcx.com/ - casino bonus codes online slots online casino real money

enetibliole (not verified)

casino play http://onlinecasinogamespcx.com/ - casino bonus codes online slots online casino real money

enetibliole (not verified)

casino play http://onlinecasinogamespcx.com/ - casino bonus codes online slots online casino real money

enetibliole (not verified)

casino play http://onlinecasinogamespcx.com/ - casino bonus codes online slots online casino real money

enetibliole (not verified)

real casino slots vegas slots online online casino best online casinos

inticleni (not verified)

http://onlinecasinosw.com/ free casino slot games vegas slots online real casino slots best online casinos

inticleni (not verified)

http://onlinecasinosw.com/ free casino slot games vegas slots online real casino slots best online casinos

inticleni (not verified)

vegas casino slots slots free casino game online slot games

enetibliole (not verified)

online slots http://onlinecasinogamespcx.com/ casino game slot games casino bonus codes

inticleni (not verified)

slots games http://onlinecasinosw.com/ slots games free online slot games casino real money

inticleni (not verified)

slots games http://onlinecasinosw.com/ slots games free online slot games casino real money

inticleni (not verified)

slots games http://onlinecasinosw.com/ slots games free online slot games casino real money

enetibliole (not verified)

play slots free online slots online casino real money online casino slots http://onlinecasinogamespcx.com/ - free casino games

enetibliole (not verified)

play slots free online slots online casino real money online casino slots http://onlinecasinogamespcx.com/ - free casino games

enetibliole (not verified)

play slots free online slots online casino real money online casino slots http://onlinecasinogamespcx.com/ - free casino games

inticleni (not verified)

http://onlinecasinosw.com/ casino slots http://onlinecasinosw.com/ - play casino casino game

enetibliole (not verified)

slots online vegas casino slots vegas slots online vegas slots online http://onlinecasinogamespcx.com/ - free slots games

inticleni (not verified)

http://onlinecasinosw.com/ free casino games online http://onlinecasinosw.com/ - play casino online casino slots

enetibliole (not verified)

casino slots http://onlinecasinopc.com/ - online casino bonus free casino games online online slots online casino slots

inticleni (not verified)

online slots online casino games world class casino slots online casino gambling http://onlinecasinosw.com/ - free casino slot games

enetibliole (not verified)

best online casinos casino blackjack slots games free

inticleni (not verified)

free casino games online play online casino casino online slots no deposit casino http://onlinecasinosw.com/ - free online slots

inticleni (not verified)

free casino games online play online casino casino online slots no deposit casino http://onlinecasinosw.com/ - free online slots

enetibliole (not verified)

http://onlinecasinopc.com/ casino real money best online casino free slots games casino play

inticleni (not verified)

slots games free http://onlinecasinosw.com/ - online casinos free casino slots for real money slots online

Add new comment