You are here

function content_taxonomy_token_values in Content Taxonomy 5

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

Implementation of hook_token_values().

File

./content_taxonomy.module, line 272
Defines a field type for referencing a taxonomy term.

Code

function content_taxonomy_token_values($type, $object = NULL) {
  if ($type == 'field') {

    // This ugly check is necessary because of some weird things going on
    // inside the content_taxonomy module: it doesn't always pass the same
    // object to CCK, and therefor Token doesn't always get a "content
    // taxonomy field object" with the same structure.
    if (isset($object['tids'])) {

      // This one is necessary for submitting content.
      $tid = reset($object['tids']);
    }
    elseif (is_array($object[0]) && is_object(reset($object[0]))) {

      // This one is necessary for viewing content.
      $term = reset($object[0]);
      $tid = $term->tid;
    }
    else {

      // This one is also sometimes necessary for viewing content...
      $tid = reset(array_keys($object));
    }
    $term = taxonomy_get_term($tid);
    $vocabulary = taxonomy_get_vocabulary($term->vid);
    $tokens['term'] = $term->name;
    $tokens['tid'] = $tid;
    $tokens['vocab'] = $vocabulary->name;
    $tokens['vid'] = $term->vid;
    return $tokens;
  }
}