You are here

function taxonomy_title_tokens in Taxonomy Title 7

Implements hook_tokens().

File

./taxonomy_title.tokens.inc, line 23
Provides tokens for the taxonomy title module.

Code

function taxonomy_title_tokens($type, $tokens, array $data = array(), array $options = array()) {
  $replacements = array();
  $sanitize = !empty($options['sanitize']);
  if ($type == 'term' && !empty($data['term'])) {
    $term = $data['term'];
    foreach ($tokens as $name => $original) {
      switch ($name) {
        case 'title':
          $title = taxonomy_title_get($term->tid);
          if ($title) {
            $replacements[$original] = $sanitize ? check_plain($title) : $title;
          }
          else {
            $name = $term->name;
            if (function_exists('i18n_taxonomy_term_name')) {
              $name = i18n_taxonomy_term_name($term);
            }
            $replacements[$original] = $sanitize ? check_plain($name) : $name;
          }
          break;
      }
    }
  }
  return $replacements;
}