You are here

function hook_pathauto_pattern_alter in Pathauto 8

Same name and namespace in other branches
  1. 6.2 pathauto.api.php \hook_pathauto_pattern_alter()
  2. 7 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

\Drupal\pathauto\PathautoPatternInterface $pattern: The Pathauto pattern to be used.

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().
  • 'bundle': 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()
PathautoGenerator::createEntityAlias in src/PathautoGenerator.php
Apply patterns to create an alias.

File

./pathauto.api.php, line 109
Documentation for pathauto API.

Code

function hook_pathauto_pattern_alter(\Drupal\pathauto\PathautoPatternInterface $pattern, array $context) {

  // Switch out any [node:created:*] tokens with [node:updated:*] on update.
  if ($context['module'] == 'node' && $context['op'] == 'update') {
    $pattern
      ->setPattern(preg_replace('/\\[node:created(\\:[^]]*)?\\]/', '[node:updated$1]', $pattern
      ->getPattern()));
  }
}