Index: content_taxonomy.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/content_taxonomy/content_taxonomy.module,v retrieving revision 1.2.2.15.2.35 diff -u -p -r1.2.2.15.2.35 content_taxonomy.module --- content_taxonomy.module 6 Feb 2010 11:40:27 -0000 1.2.2.15.2.35 +++ content_taxonomy.module 27 Oct 2010 21:25:36 -0000 @@ -18,12 +18,19 @@ function content_taxonomy_help($path, $a } /** - * Implementation of hook_init(). + * Implements hook_token_list(). */ -function content_taxonomy_init() { - if (module_exists('token')) { - module_load_include('inc', 'content_taxonomy', 'includes/content_taxonomy.token'); - } +function content_taxonomy_token_list($type = 'all') { + module_load_include('inc', 'content_taxonomy', 'includes/content_taxonomy.token'); + return _content_taxonomy_token_list($type); +} + +/** + * Implements hook_token_values(). + */ +function content_taxonomy_token_values($type, $object = NULL, $options = array()) { + module_load_include('inc', 'content_taxonomy', 'includes/content_taxonomy.token'); + return _content_taxonomy_token_values($type, $object, $options); } /** Index: includes/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 --- includes/content_taxonomy.token.inc 14 May 2009 14:30:26 -0000 1.1.2.2 +++ includes/content_taxonomy.token.inc 27 Oct 2010 21:25:36 -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,35 @@ function content_taxonomy_token_values($ if ($vid) { $vocabulary = taxonomy_vocabulary_load($vid); } + + // 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); + } + } - $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; + $values['terms-raw'] = implode(', ', $terms); + $values['terms'] = check_plain($tokens['terms-raw']); + + if (!empty($termpath_raw)) { // implode() does not like empty arrays + $values['termpath-raw'] = !empty($options['pathauto']) ? $termpath_raw : implode('/', $termpath_raw); + } + + if (!empty($termpath)) { // implode() does not like empty arrays + $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; } }