1 path.api.php hook_path_pattern_alter(&$pattern, array &$context)

Alter the pattern to be used before an alias is generated.


string $pattern: The alias pattern to pass to token_replace() to generate the URL alias.

array $context: An associative array with additional information, containing:

  • entity: The entity for which a pattern is being created.
  • source: A string of the source path for the alias (e.g. 'node/1').
  • langcode: A string of the language code for the alias (e.g. 'en').


core/modules/path/path.api.php, line 193
Hooks provided by the Path module.


function hook_path_pattern_alter(&$pattern, array &$context) {
  // Switch out any [node:created:*] tokens with [node:updated:*] on update.
  $entity = $context['entity'];
  if ($entity->entityType() == 'node' && !$entity->isNew()) {
    $pattern = preg_replace('/\[node:created(\:[^]]*)?\]/', '[node:updated$1]', $pattern);