You are here

function hook_pathauto_is_alias_reserved in Pathauto 8

Same name and namespace in other branches
  1. 7 pathauto.api.php \hook_pathauto_is_alias_reserved()

Determine if a possible URL alias would conflict with any existing paths.

Returning TRUE from this function will trigger pathauto_alias_uniquify() to generate a similar URL alias with a suffix to avoid conflicts.

Parameters

string $alias: The potential URL alias.

string $source: The source path for the alias (e.g. 'node/1').

string $langcode: The language code for the alias (e.g. 'en').

Return value

bool TRUE if $alias conflicts with an existing, reserved path, or FALSE/NULL if it does not match any reserved paths.

See also

pathauto_alias_uniquify()

1 invocation of hook_pathauto_is_alias_reserved()
AliasUniquifier::isReserved in src/AliasUniquifier.php
Checks if an alias is reserved.

File

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

Code

function hook_pathauto_is_alias_reserved($alias, $source, $langcode) {

  // Check our module's list of paths and return TRUE if $alias matches any of
  // them.
  return (bool) \Drupal::database()
    ->query("SELECT 1 FROM {mytable} WHERE path = :path", [
    ':path' => $alias,
  ])
    ->fetchField();
}