You are here

function Messaging_Template::get_tokens in Messaging 7

Get tokens for templates

File

messaging_template/messaging_template.inc, line 338
Drupal Messaging Framework - Text filtering functions

Class

Messaging_Template
Base template class

Code

function get_tokens() {
  if (!isset($this->tokens)) {
    $this->tokens = array();

    // Use template options but don't clear tokens
    $options = $this
      ->get_options();
    $objects = $this
      ->get_objects();

    // Build token groups to optimize module calls
    $token_groups = array();
    foreach ($this
      ->token_list() as $token) {
      list($type, $name) = explode(':', $token);

      // Example $tokens['site']['name'] = 'site:name'
      $token_groups[$type][$name] = $token;

      // The token defaults to itself if it can't be replaced yet
      $this->tokens[$token] = '[' . $token . ']';
    }
    foreach ($token_groups as $type => $tokens) {
      $type_tokens = token_generate($type, $tokens, $objects, $options);
      $this->tokens = $type_tokens + $this->tokens;
    }
  }
  return $this->tokens;
}