diff --git a/taxonomy_title.module b/taxonomy_title.module index 209fffa..a1ab127 100755 --- a/taxonomy_title.module +++ b/taxonomy_title.module @@ -242,21 +249,6 @@ function taxonomy_title_locale_refresh() { } /** - * Implements hook__hook_info(). - * For the tokens.inc file. - */ -function taxonomy_title_hook_info() { - $hooks['token_info'] = array( - 'group' => 'tokens', - ); - $hooks['tokens'] = array( - 'group' => 'tokens', - ); - - return $hooks; -} - -/** * Implements hook_theme(). */ function taxonomy_title_theme($existing, $type, $theme, $path) { diff --git a/taxonomy_title.tokens.inc b/taxonomy_title.tokens.inc index 04be969..5fbb22b 100644 --- a/taxonomy_title.tokens.inc +++ b/taxonomy_title.tokens.inc @@ -1,27 +1,47 @@ t('Term title'), + 'description' => t("The term's title, defaults to term name (same as [term:name]) if no title provided."), + 'needs-data' => 'term', + ); + + return $info; } /** - * Implementation of hook_token_values(). + * Implements hook_tokens(). */ -function taxonomy_title_token_values($type, $object = NULL, $options = array()) { - $values = array(); - if ($type == 'taxonomy') { - $category = $object; - // Use taxonomy title if it exists, else the category name. - $title = _taxonomy_title_get($category->tid); - $values['term-title'] = ($title) ? check_plain($title) : check_plain($category->name); - $values['term-title-raw'] = ($title) ? $title : $category->name; +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_title($term->tid); + if ($title) { + $replacements[$original] = ($sanitize) ? check_plain($title) : $title; + } + else { + $replacements[$original] = $term->name; + } + break; + } + } } - return $values; + + return $replacements; } \ No newline at end of file