You are here

public function AliasRepository::lookupByAlias in Drupal 9

Searches a path alias for a given alias.

The default implementation performs case-insensitive matching on the 'path' and 'alias' strings.

Parameters

string $alias: The alias to investigate for corresponding system paths.

string $langcode: Language code to search the alias with. If there's no alias defined for that language it will search aliases without language.

Return value

array|null An array containing the 'id', 'path', 'alias' and 'langcode' properties of a path alias, or NULL if none was found.

Overrides AliasRepositoryInterface::lookupByAlias

File

core/modules/path_alias/src/AliasRepository.php, line 75

Class

AliasRepository
Provides the default path alias lookup operations.

Namespace

Drupal\path_alias

Code

public function lookupByAlias($alias, $langcode) {

  // See the queries above. Use LIKE for case-insensitive matching.
  $select = $this
    ->getBaseQuery()
    ->fields('base_table', [
    'id',
    'path',
    'alias',
    'langcode',
  ])
    ->condition('base_table.alias', $this->connection
    ->escapeLike($alias), 'LIKE');
  $this
    ->addLanguageFallback($select, $langcode);
  $select
    ->orderBy('base_table.id', 'DESC');
  return $select
    ->execute()
    ->fetchAssoc() ?: NULL;
}