1 path.module path_is_alias_reserved($alias, $source, $langcode = LANGUAGE_NONE)

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

Returning TRUE from this function will trigger path_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 if it does not match any reserved paths.

File

core/modules/path/path.module, line 969
Enables users to customize URLs and provide automatic URL alias patterns.

Code

function path_is_alias_reserved($alias, $source, $langcode = LANGUAGE_NONE) {
  $is_existing_alias = (bool) db_query_range("SELECT pid FROM {url_alias} WHERE source <> :source AND alias = :alias AND langcode IN (:language, :language_none) ORDER BY langcode DESC, pid DESC", 0, 1, array(
    ':source' => $source,
    ':alias' => $alias,
    ':language' => $langcode,
    ':language_none' => LANGUAGE_NONE,
  ))->fetchField();

  if ($is_existing_alias) {
    return TRUE;
  }

  module_load_include('inc', 'path');
  if (_path_is_callback($alias)) {
    return TRUE;
  }

  foreach (module_implements('path_is_alias_reserved') as $module) {
    $result = module_invoke($module, 'path_is_alias_reserved', $alias, $source, $langcode);
    if (!empty($result)) {
      // As soon as the first module says that an alias is in fact reserved,
      // then there is no point in checking the rest of the modules.
      return TRUE;
    }
  }

  return FALSE;
}