In Drupal 8, my custom module includes the code

if (\Drupal::service('path.alias_storage')->aliasExists($path, 'en')) {
    return true;

What should this look like in Drupal 9.2? Seems so simple, but I can't figure it out after reading every post I can find.


1 Answer 1


This service was deprecated in Drupal 8 and removed in Drupal 9.

Path aliases were converted to an entity. You can use the entity storage and additionally the path_alias.repository service for some common case-insensitive lookups:

$path_alias_repository = \Drupal::service('path_alias.repository');
if ($path_alias_repository->lookupByAlias($alias, 'en')) {
  return TRUE;

Interesting is that the service AliasRepository provides a pathHasMatchingAlias() method but not one for the other direction, so you have to check whether the lookup method above returns a result.


Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.