class AliasStorage implements AliasStorageInterface (View source)

deprecated \Drupal\Core\Path\AliasStorage is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use the "path_alias.repository" service instead, or the entity storage handler for the "path_alias" entity type for CRUD methods.

Provides a class for CRUD operations on path aliases.

All queries perform case-insensitive matching on the 'source' and 'alias' fields, so the aliases '/test-alias' and '/test-Alias' are considered to be the same, and will both refer to the same internal system path.

Constants

TABLE

The table for the url_alias storage.

Properties

protected Connection $connection

The database connection.

protected ModuleHandlerInterface $moduleHandler

The module handler.

protected EntityTypeManagerInterface $entityTypeManager

The entity type manager.

Methods

__construct(Connection $connection, ModuleHandlerInterface $module_handler, EntityTypeManagerInterface $entity_type_manager = NULL)

Constructs a Path CRUD object.

array|false
save(string $source, string $alias, string $langcode = LanguageInterface::LANGCODE_NOT_SPECIFIED, int|null $pid = NULL)

Saves a path alias to the database.

array|false
load(array $conditions)

Fetches a specific URL alias from the database.

delete(array $conditions)

Deletes a URL alias.

getBaseQuery()

Returns a SELECT query for the path_alias base table.

string[]
preloadPathAlias(array $preloaded, string $langcode)

Pre-loads path alias information for a given list of source paths.

string|false
lookupPathAlias(string $path, string $langcode)

Returns an alias of Drupal system URL.

string|false
lookupPathSource($alias, string $langcode)

Returns Drupal system URL of an alias.

addLanguageFallback(SelectInterface $query, string $langcode)

Adds path alias language fallback conditions to a select query object.

bool
aliasExists(string $alias, string $langcode, string|null $source = NULL)

Checks if alias already exists.

bool
languageAliasExists()

Checks if there are any aliases with language defined.

array
getAliasesForAdminListing(array $header, string|null $keys = NULL)

Loads aliases for admin listing.

bool
pathHasMatchingAlias(string $initial_substring)

Check if any alias exists starting with $initial_substring.

getPathAliasEntityStorage()

Returns the path alias entity storage handler.

Details

__construct(Connection $connection, ModuleHandlerInterface $module_handler, EntityTypeManagerInterface $entity_type_manager = NULL)

Constructs a Path CRUD object.

Parameters

Connection $connection

A database connection for reading and writing path aliases.

ModuleHandlerInterface $module_handler

The module handler.

EntityTypeManagerInterface $entity_type_manager

The entity type manager.

array|false save(string $source, string $alias, string $langcode = LanguageInterface::LANGCODE_NOT_SPECIFIED, int|null $pid = NULL)

Saves a path alias to the database.

Parameters

string $source

The internal system path.

string $alias

The URL alias.

string $langcode

(optional) The language code of the alias.

int|null $pid

(optional) Unique path alias identifier.

Return Value

array|false

FALSE if the path could not be saved or an associative array containing the following keys:

  • source (string): The internal system path with a starting slash.
  • alias (string): The URL alias with a starting slash.
  • pid (int): Unique path alias identifier.
  • langcode (string): The language code of the alias.
  • original: For updates, an array with source, alias and langcode with the previous values.

array|false load(array $conditions)

Fetches a specific URL alias from the database.

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

Parameters

array $conditions

An array of query conditions.

Return Value

array|false

FALSE if no alias was found or an associative array containing the following keys:

  • source (string): The internal system path with a starting slash.
  • alias (string): The URL alias with a starting slash.
  • pid (int): Unique path alias identifier.
  • langcode (string): The language code of the alias.

delete(array $conditions)

Deletes a URL alias.

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

Parameters

array $conditions

An array of criteria.

protected SelectInterface getBaseQuery()

Returns a SELECT query for the path_alias base table.

Return Value

SelectInterface

A Select query object.

string[] preloadPathAlias(array $preloaded, string $langcode)

Pre-loads path alias information for a given list of source paths.

Parameters

array $preloaded

Paths that need preloading of aliases.

string $langcode

Language code to search the path with. If there's no path defined for that language it will search paths without language.

Return Value

string[]

Source (keys) to alias (values) mapping.

string|false lookupPathAlias(string $path, string $langcode)

Returns an alias of Drupal system URL.

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

Parameters

string $path

The path to investigate for corresponding path aliases.

string $langcode

Language code to search the path with. If there's no path defined for that language it will search paths without language.

Return Value

string|false

A path alias, or FALSE if no path was found.

string|false lookupPathSource($alias, string $langcode)

Returns Drupal system URL of an alias.

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

Parameters

$alias
string $langcode

Language code to search the path with. If there's no path defined for that language it will search paths without language.

Return Value

string|false

A Drupal system path, or FALSE if no path was found.

protected addLanguageFallback(SelectInterface $query, string $langcode)

Adds path alias language fallback conditions to a select query object.

Parameters

SelectInterface $query

A Select query object.

string $langcode

Language code to search the path with. If there's no path defined for that language it will search paths without language.

bool aliasExists(string $alias, string $langcode, string|null $source = NULL)

Checks if alias already exists.

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

Parameters

string $alias

Alias to check against.

string $langcode

Language of the alias.

string|null $source

(optional) Path that alias is to be assigned to.

Return Value

bool

TRUE if alias already exists and FALSE otherwise.

bool languageAliasExists()

Checks if there are any aliases with language defined.

Return Value

bool

TRUE if aliases with language exist.

array getAliasesForAdminListing(array $header, string|null $keys = NULL)

Loads aliases for admin listing.

Parameters

array $header

Table header.

string|null $keys

(optional) Search keyword that may include one or more '*' as wildcard values.

Return Value

array

Array of items to be displayed on the current page.

bool pathHasMatchingAlias(string $initial_substring)

Check if any alias exists starting with $initial_substring.

Parameters

string $initial_substring

Initial path substring to test against.

Return Value

bool

TRUE if any alias exists, FALSE otherwise.

protected EntityStorageInterface getPathAliasEntityStorage()

Returns the path alias entity storage handler.

We can not store it in the constructor because that leads to a circular dependency in the service container.

Return Value

EntityStorageInterface

The path alias entity storage.