? 881270-pathauto-path-tokens.patch ? 881270-pathauto-path-tokens_120.patch Index: pathauto.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/pathauto/pathauto.inc,v retrieving revision 1.45.2.28 diff -u -p -r1.45.2.28 pathauto.inc --- pathauto.inc 12 Aug 2010 15:11:08 -0000 1.45.2.28 +++ pathauto.inc 27 Sep 2010 14:19:22 -0000 @@ -543,9 +543,11 @@ function pathauto_get_placeholders($type watchdog('Pathauto', 'It appears that you have installed Pathauto, which depends on token, but token is either not installed or not installed properly.'); return array('tokens' => array(), 'values' => array()); } - $full = token_get_values($type, $object, TRUE); + + $options = array('pathauto' => TRUE); + $full = token_get_values($type, $object, TRUE, $options); $tokens = token_prepare_tokens($full->tokens); - $values = pathauto_clean_token_values($full); + $values = pathauto_clean_token_values($full, $options); return array('tokens' => $tokens, 'values' => $values); } @@ -559,24 +561,26 @@ function pathauto_get_placeholders($type * @return * An array of the cleaned tokens. */ -function pathauto_clean_token_values($full) { +function pathauto_clean_token_values($full, $options = array()) { $replacements = array(); foreach ($full->values as $key => $value) { - // Only clean non-path tokens. $token = $full->tokens[$key]; - if (!preg_match('/(path|alias|url|url-brief)(-raw)?$/', $token)) { - $replacements[$token] = pathauto_cleanstring($value); - } - elseif (preg_match('/(bookpath|menupath)(-raw)?$/', $token)) { - // A few tokens violate the path/path-raw naming convention and should - // still have their segments cleaned using pathauto_cleanstring(). - $segments = explode('/', $value); - $segments = array_map('pathauto_cleanstring', $segments); + if (strpos($token, 'path') !== FALSE && is_array($value) && !empty($options['pathauto'])) { + // If the token name contains 'path', the token value is an array, and + // the 'pathauto' option was passed to token_get_values(), then the token + // should have each segment cleaned, and then glued back together to + // construct an value resembling an URL. + $segments = array_map('pathauto_cleanstring', $value); $replacements[$token] = implode('/', $segments); } - else { + elseif (preg_match('/(path|alias|url|url-brief)(-raw)?$/', $token)) { + // Token name matches an URL-type name and should be left raw. $replacements[$token] = $value; } + else { + // Tokens is not an URL, so it should have its value cleaned. + $replacements[$token] = pathauto_cleanstring($value); + } } return $replacements; } Index: pathauto.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/pathauto/pathauto.module,v retrieving revision 1.118.2.29 diff -u -p -r1.118.2.29 pathauto.module --- pathauto.module 11 Aug 2010 19:38:26 -0000 1.118.2.29 +++ pathauto.module 27 Sep 2010 14:19:22 -0000 @@ -166,12 +166,11 @@ function pathauto_token_values($type, $o $parents = taxonomy_get_parents_all($object->tid); $catpath = $catpath_raw = array(); foreach ($parents as $parent) { - $term_name_cleaned = pathauto_cleanstring($parent->name); - array_unshift($catpath, check_plain($term_name_cleaned)); - array_unshift($catpath_raw, $term_name_cleaned); + array_unshift($catpath, check_plain($parent->name)); + array_unshift($catpath_raw, $parent->name); } - $values[$label . 'path'] = implode('/', $catpath); - $values[$label . 'path-raw'] = implode('/', $catpath_raw); + $values[$label . 'path'] = !empty($options['pathauto']) ? $catpath : implode('/', $catpath); + $values[$label . 'path-raw'] = !empty($options['pathauto']) ? $catpath_raw : implode('/', $catpath_raw); // Token [catalias-raw] and [catalias]. $values[$label . 'alias-raw'] = drupal_get_path_alias(taxonomy_term_path($object)); Index: pathauto.test =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/pathauto/pathauto.test,v retrieving revision 1.1.2.10 diff -u -p -r1.1.2.10 pathauto.test --- pathauto.test 11 Aug 2010 19:38:26 -0000 1.1.2.10 +++ pathauto.test 27 Sep 2010 14:19:22 -0000 @@ -29,8 +29,8 @@ class PathautoTestHelper extends DrupalW } function assertToken($type, $object, $token, $expected) { - $tokens = pathauto_token_values($type, $object); - $this->assertEqual($tokens[$token], $expected, t("Token value for [@token] was '!actual', expected value '!expected'.", array('@token' => $token, '!actual' => $tokens[$token], '!expected' => $expected))); + $tokens = pathauto_get_placeholders($type, $object); + $this->assertEqual($tokens['values'][$token], $expected, t("Token value for [@token] was '!actual', expected value '!expected'.", array('@token' => $token, '!actual' => $tokens['values'][$token], '!expected' => $expected))); } function saveAlias($source, $alias, $language = '') {