-
-
Save mohammadanwar/59a4d5b485f2bb64c9e5a0070203893e to your computer and use it in GitHub Desktop.
Drupal 8 Get node ID by path alias
This file contains hidden or 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