You are here

function token_custom_tokens in Custom Tokens 7.2

Same name and namespace in other branches
  1. 8 token_custom.module \token_custom_tokens()
  2. 7 token_custom.module \token_custom_tokens()

Implements hook_tokens().

File

./token_custom.module, line 172
It gives the user the ability to create custom tokens using PHP code for specific replacements that can improve other modules relying on the token Drupal 7 core API.

Code

function token_custom_tokens($type, $tokens, array $data = array(), array $options = array()) {
  $return = array();

  // Load all our custom modules mentionned in the $tokens array.
  $custom_tokens = token_custom_load_multiple(array_keys($tokens));
  foreach ($custom_tokens as $machine_name => $custom_token) {
    if ($type == $custom_token->type && array_key_exists($machine_name, $tokens)) {
      $return[$tokens[$machine_name]] = token_custom_token_render($machine_name, $custom_token->content, $data, $options);
    }
  }
  return $return;
}