Index: content_taxonomy.token.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/content_taxonomy/includes/Attic/content_taxonomy.token.inc,v retrieving revision 1.1.2.2 diff -u -p -r1.1.2.2 content_taxonomy.token.inc --- content_taxonomy.token.inc 14 May 2009 14:30:26 -0000 1.1.2.2 +++ content_taxonomy.token.inc 12 Oct 2010 22:57:15 -0000 @@ -3,8 +3,9 @@ /** * Implementation of hook_token_list(). */ -function content_taxonomy_token_list($type = 'all') { +function _content_taxonomy_token_list($type = 'all') { if ($type == 'field' || $type == 'all') { + $tokens = array(); $tokens['content_taxonomy']['term'] = t('Name of top taxonomy term'); @@ -12,10 +13,12 @@ function content_taxonomy_token_list($ty $tokens['content_taxonomy']['tid'] = t('ID of top taxonomy term'); $tokens['content_taxonomy']['terms'] = t('Names of all taxonomy terms separated by commas'); $tokens['content_taxonomy']['terms-raw'] = t('Unfiltered names of all taxonomy terms separated by commas. WARNING - raw user input.'); + $tokens['content_taxonomy']['termpath'] = t('Name of top taxonomy term and its supercategories separated by /'); + $tokens['content_taxonomy']['termpath-raw'] = t('Name of top taxonomy term and its supercategories separated by /. WARNING - raw user input.'); $tokens['content_taxonomy']['tids'] = t('IDs of all taxonomy terms separated by commas'); $tokens['content_taxonomy']['vocab'] = t('Name of terms vocabulary'); $tokens['content_taxonomy']['vid'] = t('ID of terms vocabulary'); - + return $tokens; } } @@ -23,8 +26,9 @@ function content_taxonomy_token_list($ty /** * Implementation of hook_token_values(). */ -function content_taxonomy_token_values($type, $object = NULL) { +function _content_taxonomy_token_values($type, $object = NULL, $options = array()) { if ($type == 'field') { + $values = array(); $items = $object; $terms = array(); $tids = array(); @@ -41,16 +45,28 @@ function content_taxonomy_token_values($ 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'] = $terms[0]; - $tokens['term'] = check_plain($tokens['term-raw']); - $tokens['tid'] = $tids[0]; - $tokens['vocab'] = isset($vocabulary) ? $vocabulary->name : ''; - $tokens['vid'] = $vid; - - return $tokens; + + // Gather term hierarchy, but only for the first term. + if (count($tids)) { + $parents = taxonomy_get_parents_all($tids[0]); + $termpath = $termpath_raw = array(); + foreach ($parents as $parent) { + array_unshift($termpath, check_plain($parent->name)); + array_unshift($termpath_raw, $parent->name); + } + } + + $values['terms-raw'] = implode(', ', $terms); + $values['terms'] = check_plain($tokens['terms-raw']); + $values['termpath-raw'] = !empty($options['pathauto']) ? $termpath_raw : implode('/', $termpath_raw); + $values['termpath'] = !empty($options['pathauto']) ? $termpath : implode('/', $termpath); + $values['tids'] = implode(', ', $tids); + $values['term-raw'] = $terms[0]; + $values['term'] = check_plain($tokens['term-raw']); + $values['tid'] = $tids[0]; + $values['vocab'] = isset($vocabulary) ? $vocabulary->name : ''; + $values['vid'] = $vid; + + return $values; } }