You are here

function content_taxonomy_token_values in Content Taxonomy 6

Same name and namespace in other branches
  1. 5 content_taxonomy.module \content_taxonomy_token_values()
  2. 6.2 includes/content_taxonomy.token.inc \content_taxonomy_token_values()

Implementation of hook_token_values().

File

includes/content_taxonomy.token.inc, line 26

Code

function content_taxonomy_token_values($type, $object = NULL) {
  if ($type == 'field') {
    $items = $object;
    $terms = array();
    $tids = array();
    $vid = FALSE;
    foreach ($items as $item) {
      $tid = $item['value'];
      if ($tid) {
        $term = taxonomy_get_term($tid);
        $tids[] = $tid;
        $terms[] = $term->name;
        $vid = $term->vid;
      }
    }
    if ($vid) {
      $vocabulary = taxonomy_vocabulary_load($vid);
    }
    $tokens['terms-raw'] = implode(', ', $terms);
    $tokens['terms'] = check_plain($tokens['terms-raw']);
    $tokens['tids'] = implode(', ', $tids);
    $tokens['term-raw'] = reset($terms);
    $tokens['term'] = check_plain($tokens['term-raw']);
    $tokens['tid'] = reset($tids);
    $tokens['vocab'] = isset($vocabulary) ? $vocabulary->name : '';
    $tokens['vid'] = $vid;
    return $tokens;
  }
}