class AliasManager implements AliasManagerInterface (View source)

The default alias manager implementation.

Properties

protected AliasRepositoryInterface $pathAliasRepository

The path alias repository.

protected CacheBackendInterface $cache

Cache backend service.

protected string $cacheKey

The cache key to use when caching paths.

protected bool $cacheNeedsWriting

Whether the cache needs to be written.

protected LanguageManagerInterface $languageManager

Language manager for retrieving the default langcode when none is specified.

protected array $lookupMap

Holds the map of path lookups per language.

protected array $noPath

Holds an array of aliases for which no path was found.

protected AliasWhitelistInterface $whitelist

Holds the array of whitelisted path aliases.

protected array $noAlias

Holds an array of paths that have no alias.

protected array $langcodePreloaded

Whether preloaded path lookups has already been loaded.

protected array $preloadedPathLookups

Holds an array of previously looked up paths for the current request path.

Methods

__construct(AliasRepositoryInterface $alias_repository, AliasWhitelistInterface $whitelist, LanguageManagerInterface $language_manager, CacheBackendInterface $cache)

Constructs an AliasManager.

setCacheKey($key)

{@inheritdoc}

writeCache()

{@inheritdoc}

string
getPathByAlias(string $alias, string $langcode = NULL)

Given the alias, return the path it represents.

string
getAliasByPath(string $path, string $langcode = NULL)

Given a path, return the alias.

cacheClear($source = NULL)

Clears the static caches in alias manager and rebuilds the whitelist.

An
pathAliasWhitelistRebuild(string $path = NULL)

Rebuild the path alias white list.

int
getRequestTime()

Wrapper method for REQUEST_TIME constant.

Details

__construct(AliasRepositoryInterface $alias_repository, AliasWhitelistInterface $whitelist, LanguageManagerInterface $language_manager, CacheBackendInterface $cache)

Constructs an AliasManager.

Parameters

AliasRepositoryInterface $alias_repository

The path alias repository.

AliasWhitelistInterface $whitelist

The whitelist implementation to use.

LanguageManagerInterface $language_manager

The language manager.

CacheBackendInterface $cache

Cache backend.

setCacheKey($key)

{@inheritdoc}

Parameters

$key

writeCache()

{@inheritdoc}

Cache an array of the paths available on each page. We assume that aliases will be needed for the majority of these paths during subsequent requests, and load them in a single query during path alias lookup.

string getPathByAlias(string $alias, string $langcode = NULL)

Given the alias, return the path it represents.

Parameters

string $alias

An alias.

string $langcode

An optional language code to look up the path in.

Return Value

string

The path represented by alias, or the alias if no path was found.

Exceptions

InvalidArgumentException

string getAliasByPath(string $path, string $langcode = NULL)

Given a path, return the alias.

Parameters

string $path

A path.

string $langcode

An optional language code to look up the path in.

Return Value

string

An alias that represents the path, or path if no alias was found.

Exceptions

InvalidArgumentException

cacheClear($source = NULL)

Clears the static caches in alias manager and rebuilds the whitelist.

Parameters

$source

Source path of the alias that is being inserted/updated. If omitted, the entire lookup static cache will be cleared and the whitelist will be rebuilt.

protected An pathAliasWhitelistRebuild(string $path = NULL)

Rebuild the path alias white list.

Parameters

string $path

An optional path for which an alias is being inserted.

Return Value

An

array containing a white list of path aliases.

protected int getRequestTime()

Wrapper method for REQUEST_TIME constant.

Return Value

int