4

I want to get all the path aliases defined for a route. Using AliasStorage::lookupPathAlias() or AliasManager::getAliasByPath(), I get a single path alias, even when there are more path aliases defined for that route.

If I were using Drupal 7, I would use the answers given to Find all aliases for a given node.

How can I get all the path aliases defined for a single route?

1 Answer 1

2

The answer is the same as in Drupal 7, because there is no API to return multiple aliases for a single source path, so your only option, if you really need that (I guess there is a reason that you are not using redirects), is a custom query, which is the same as in 7.x, with the only difference that it has a leading /.

So, copied from the other issue:

$aliases = \Drupal::database()->query('
  SELECT alias
  FROM {url_alias}
  WHERE source = :source
', array(':source' => '/node/' . $nid))->fetchAll();
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.