1.20.x path.api.php hook_path_alias_alter(&$alias, array &$context)

Alter generated aliases before saving.

Parameters

string $alias: The automatic alias after token replacement and strings cleaned.

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').

File

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

Code

function hook_path_alias_alter(&$alias, array &$context) {
  // Add a suffix so that all aliases get saved as 'content/my-title.html'
  $alias .= '.html';

  // Force all aliases to be saved as language neutral.
  $context['langcode'] = LANGUAGE_NONE;
}