Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

drupal 8 get node from path alias

// Get node from path alias.
$path = Drupal::service('path.alias_manager')->getPathByAlias('/this-is-the-alias');

if(preg_match('/node/(d+)/', $path, $matches)) {
  $node = Drupal
odeEntityNode::load($matches[1]);
}

// Path alias manager service has been change to 'path_alias.manager' on later version.
$path = Drupal::service('path_alias.manager')->getPathByAlias('/this-is-the-alias');
 
PREVIOUS NEXT
Tagged: #drupal #node #path #alias
ADD COMMENT
Topic
Name
8+8 =