hi
Please i need help on how to.

i would like to expose some token to user so that they may use it for calculation.
But i am looking for a way to rewrite token that will be expose to users...
Instead of [node:title] i want it to be something like [champ:onu] or [$onu] ... a more friendly readable token .

Can this module help to do that ?

thanks

Comments

delacosta456 created an issue.

saurabh.dhariwal’s picture

You can achive this by creating your own custom token. This can be done in 2 ways:

1. Use Custom Tokens module to generate custom tokens like [champ:onu] or [$onu]

2. You can also create tokens programatically. Add following code in any custom module file.

/**
 * Implements hook_token_info().
 */
function MYMODULE_token_info() { 
  $info['tokens']['custom']['token_machine_name'] = array(
    'name' => t('Token name'),
    'description' => t('Description for token'),
  );
  return $info;
}

/**
 * Implements hook_tokens().
 * This hook will operate the token and replace it with value.
 */
function MYMODULE_tokens($type, $tokens, array $data = array(), array $options = array()) {
  $replacements = array();   
  foreach ($tokens as $value => $original) {     
    switch ($value) {
      case 'token_machine_name':
        // you can write your logic here to add the value in token
        $value = 'Value of token';
        $replacements[$original] = $value;
        break;
    }
  }
  return $replacements;  
}

After tokens are generated, use Token Insert module to allow users to add token in wysiwyg editor.

Let me know incase of any query/concern.

Thanks!