Skip to content

Instantly share code, notes, and snippets.

@thagler
Created September 16, 2016 02:40
Show Gist options
  • Save thagler/d7c47a2aa5d2ba3fe113afcc69995489 to your computer and use it in GitHub Desktop.
Save thagler/d7c47a2aa5d2ba3fe113afcc69995489 to your computer and use it in GitHub Desktop.
Drupal 8 Get node ID by path alias
<?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