Skip to content

Instantly share code, notes, and snippets.

@mohammadanwar
Forked from thagler/get_node_by_path.php
Created August 28, 2024 06:46
Show Gist options
  • Select an option

  • Save mohammadanwar/59a4d5b485f2bb64c9e5a0070203893e to your computer and use it in GitHub Desktop.

Select an option

Save mohammadanwar/59a4d5b485f2bb64c9e5a0070203893e to your computer and use it in GitHub Desktop.

Revisions

  1. Tobby Hagler revised this gist Sep 16, 2016. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions get_node_by_path.php
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,5 @@
    <?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]);
  2. Tobby Hagler created this gist Sep 16, 2016.
    4 changes: 4 additions & 0 deletions get_node_by_path.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,4 @@
    $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]);
    }