-
-
Save crittermike/4e559ac299efe8485a256a6a144c77e3 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]); | |
} |
stloc
commented
Dec 5, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment