Index: modules/hs_taxonomy.module =================================================================== --- modules/hs_taxonomy.module (revision 10) +++ modules/hs_taxonomy.module (working copy) @@ -609,6 +609,11 @@ $separator = variable_get('hs_taxonomy_separator', variable_get('pathauto_separator', '-')); + if (module_exists('pathauto')) { + // Required from the pathauto_cleanstring() function, used for alias token. + module_load_include('inc', 'pathauto', 'pathauto'); + } + $values = array(); switch ($type) { case 'node': @@ -642,29 +647,51 @@ } } + // Build consistency to handle all three forms of $node->taxonomy + foreach ($node->taxonomy as $key => $item) { + if (is_object($item)) { + $terms_by_vocab[$item->vid][$item->tid] = $item->tid; + } + elseif (is_array($item)) { + foreach ($item as $index => $term) { + $term = is_object($term) ? $term : taxonomy_get_term($term); + $terms_by_vocab[$term->vid][$term->tid] = $term->tid; + } + } + elseif (is_numeric($item)) { + $term = taxonomy_get_term($item); + $terms_by_vocab[$term->vid][$term->tid] = $term->tid; + } + } + // Generate the per-vid "save-lineage-termpath" tokens. foreach ($all_vids as $vid) { $terms = array(); if (in_array($vid, $hs_vids) && isset($node->taxonomy[$vid])) { - $selection = $node->taxonomy[$vid]; + $selection = $terms_by_vocab[$vid]; $terms = _hs_taxonomy_token_termpath_for_vid($selection, $vid); } $values["save-lineage-termpath:$vid"] = implode($separator, array_map('check_plain', $terms)); $values["save-lineage-termpath-raw:$vid"] = implode($separator, $terms); + if (module_exists('pathauto')) { + $values["save-lineage-termpath-alias-raw:$vid"] = implode('/', array_map('pathauto_cleanstring', $terms)); + } } // We use the terms of the first vocabulary that uses Hierarchical // Select for the default "save-lineage-termpath" tokens. - $vids = array_intersect(array_keys($node->taxonomy), $hs_vids); + $vids = array_intersect(array_keys($terms_by_vocab), $hs_vids); if (!empty($vids)) { $vid = $vids[0]; - $values['save-lineage-termpath'] = implode($separator, array_map('check_plain', $terms)); - $values['save-lineage-termpath-raw'] = implode($separator, $terms); + $values['save-lineage-termpath'] = $values['save-lineage-termpath:' . $vid]; + $values['save-lineage-termpath-raw'] = $values['save-lineage-termpath-raw:' . $vid]; + if (module_exists('pathauto')) { + $values['save-lineage-termpath-alias-raw'] = $values['save-lineage-termpath-alias-raw:' . $vid]; + } } break; } - return $values; } @@ -675,9 +702,11 @@ if ($type == 'node' || $type == 'all') { $tokens['node']['save-lineage-termpath'] = t('Only use when you have enabled the "save lineage" setting of Hierarchical Select. Will show the term\'s parent terms separated by /.'); $tokens['node']['save-lineage-termpath-raw'] = t('As [save-linage-termpath]. WARNING - raw user input.'); + $tokens['node']['save-lineage-termpath-alias-raw'] = t('As [save-linage-termpath-raw], but in url alias fashion. WARNING - raw user input.'); $tokens['node']['save-lineage-termpath:vid'] = t('Only has output when terms are present for the vocabulary with the specified vid. Only use when you have enabled the "save lineage" setting of Hierarchical Select. Will show the term\'s parent terms separated by /.'); - $tokens['node']['save-lineage-termpath-raw:vid'] = t('Only has output when terms are present for the vocabulary with the specified vid. As [save-linage-termpath]. WARNING - raw user input.'); + $tokens['node']['save-lineage-termpath-raw:vid'] = t('Only has output when terms are present for the vocabulary with the specified vid. As [save-linage-termpath-raw]. WARNING - raw user input.'); + $tokens['node']['save-lineage-termpath-alias-raw:vid'] = t('Only has output when terms are present for the vocabulary with the specified vid. As [save-linage-termpath-aliss]. WARNING - raw user input.'); return $tokens; }