4

drupal_lookup_path() have been remove in Drupal 8. However, I cannot find a way to achieve the same functionality. All, I'm trying to do is to provide Drupal with a path and he is going to look to see if exist, if exist is going to provide me the node id. If does not exist that path he going to give me an error or null/0.

How can I achieve this on Drupal 8?

4

Drupal 7:

$path .= drupal_lookup_path('alias', $path);

Drupal 8:

$alias = 
  \Drupal::service('path.alias_manager')
    ->getPathAlias($path);

if (strcmp($alias, $path) == 0) {
  $alias = '';  // No alias was found.
}

$path .= $alias;

Reference Link

8 calls to drupal_lookup_path()

  • 3
    This does not apply any more. getPathAlias() have change to getAliasByPath(). – itsdarrylnorris Jun 11 '15 at 18:42
3

In my case i got it work by using this

$path = "certainpath"; $alias = \Drupal::service('path.alias_storage')->aliasExists($path, 'en');

it will return true if path exists.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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