/Drupal 8

public function AliasManager::getPathByAlias

public AliasManager::getPathByAlias($alias, $langcode = NULL)

Given the alias, return the path it represents.


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.


\InvalidArgumentException Thrown when the path does not start with a slash.

Overrides AliasManagerInterface::getPathByAlias


core/lib/Drupal/Core/Path/AliasManager.php, line 151


The default alias manager implementation.




public function getPathByAlias($alias, $langcode = NULL) {
  // If no language is explicitly specified we default to the current URL
  // language. If we used a language different from the one conveyed by the
  // requested URL, we might end up being unable to check if there is a path
  // alias matching the URL path.
  $langcode = $langcode ? : $this->languageManager->getCurrentLanguage(LanguageInterface::TYPE_URL)->getId();

  // If we already know that there are no paths for this alias simply return.
  if (empty($alias) || !empty($this->noPath[$langcode][$alias])) {
    return $alias;

  // Look for the alias within the cached map.
  if (isset($this->lookupMap[$langcode]) && ($path = array_search($alias, $this->lookupMap[$langcode]))) {
    return $path;

  // Look for path in storage.
  if ($path = $this->storage->lookupPathSource($alias, $langcode)) {
    $this->lookupMap[$langcode][$path] = $alias;
    return $path;

  // We can't record anything into $this->lookupMap because we didn't find any
  // paths for this alias. Thus cache to $this->noPath.
  $this->noPath[$langcode][$alias] = TRUE;

  return $alias;

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.