-
-
Save manojiksula/9bb1d0bd5c7b702c344f21f98fa77b21 to your computer and use it in GitHub Desktop.
Drupal 8 Get node ID by path alias
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$path = \Drupal::service('path.alias_manager')->getPathByAlias('/this-is-the-alias'); | |
if(preg_match('/node\/(\d+)/', $path, $matches)) { | |
$node = \Drupal\node\Entity\Node::load($matches[1]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Drupal 9+ Get node ID by path alias: