Using path style tokens
Pathauto enforces a couple standards when writing or using 'path' style tokens like 'root/subpage/page'.
Path and URL tokens are left alone by Pathauto...
Token names that end with the word 'path', 'alias', 'url', 'url-brief' (or any of the previous words with '-raw' appended) will be left untouched and not have pathauto_cleanstring() applied to it. This is because these tokens are assumed to be actual aliases or URLs and therefore may have already be processed by Pathauto.
...except for tokens with 'path' in the name and who's corresponding value is an array of segments
For example, if your module provides a token called 'object-path' that provides a 'fake' path-style token composed of separate components, and you want Pathauto to be able to clean the individual segments, you'll need to provide the token value as an array of segments if $options['pathauto'] = TRUE.
This is available only when using Pathauto 1.5+ or 2.0-alpha3+ in combination with Token 6.15+. A more proper solution is being considered for D7 token API.
Before:
function mymodule_token_values($type, $object = NULL, $options = array()) {
$values = array();
$object_path_raw = array($object->root_name, $object->parent_name, $object->name);
$object_path = array_map('check_plain', $my_token_path_raw);
$values['object-path-raw'] = implode($object_path_raw, '/');
$values['object-path'] = implode($object_path, '/');
return $values;
}
After:
function mymodule_token_values($type, $object = NULL, $options = array()) {
$values = array();
$object_path_raw = array($object->root_name, $object->parent_name, $object->name);
$object_path = array_map('check_plain', $my_token_path_raw);
$values['object-path-raw'] = !empty($options['pathauto']) ? $object_path_raw : implode('/', $object_path_raw);
$values['object-path'] = !empty($options['pathauto']) ? $object_path : implode('/', $object_path);
return $values;
}
Help improve this page
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion