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 971
Enables users to customize URLs and provide automatic URL alias patterns.

Code

function path_is_alias_reserved($alias, $source, $langcode = LANGUAGE_NONE) {
  $query = db_select('url_alias')
    ->condition('source', $source, '<>')
    ->condition('alias', $alias);
  // Language neutral would always collide, an alias with language only collides
  // with the same language or language neutral.
  if ($langcode != LANGUAGE_NONE) {
    $query->condition('langcode', array($langcode, LANGUAGE_NONE), 'IN');
  }
  $is_existing_alias = $query->countQuery()->execute()->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;
}