function hook_pathauto_pattern_alter in Pathauto 7
Same name and namespace in other branches
- 8 pathauto.api.php \hook_pathauto_pattern_alter()
- 6.2 pathauto.api.php \hook_pathauto_pattern_alter()
Alter the pattern to be used before an alias is generated by Pathauto.
This hook will only be called if a default pattern is configured (on admin/config/search/path/patterns).
Parameters
string $pattern: The alias pattern for Pathauto to pass to token_replace() to generate the URL alias.
array $context: An associative array of additional options, with the following elements:
- 'module': The module or entity type being aliased.
- 'op': A string with the operation being performed on the object being aliased. Can be either 'insert', 'update', 'return', or 'bulkupdate'.
- 'source': A string of the source path for the alias (e.g. 'node/1').
- 'data': An array of keyed objects to pass to token_replace().
- 'type': The sub-type or bundle of the object being aliased.
- 'language': A string of the language code for the alias (e.g. 'en'). This can be altered by reference.
1 invocation of hook_pathauto_pattern_alter()
- pathauto_create_alias in ./
pathauto.inc - Apply patterns to create an alias.
File
- ./
pathauto.api.php, line 164 - Documentation for pathauto API.
Code
function hook_pathauto_pattern_alter(&$pattern, array $context) {
// Switch out any [node:created:*] tokens with [node:updated:*] on update.
if ($context['module'] == 'node' && $context['op'] == 'update') {
$pattern = preg_replace('/\\[node:created(\\:[^]]*)?\\]/', '[node:updated$1]', $pattern);
}
}