Skip to content

Instantly share code, notes, and snippets.

@leymannx
Created August 19, 2016 11:38
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leymannx/6cdc544354332ba58619f5146a9ae358 to your computer and use it in GitHub Desktop.
Save leymannx/6cdc544354332ba58619f5146a9ae358 to your computer and use it in GitHub Desktop.
Drupal 8 menu get object
<?php
$node = Drupal::request()->attributes->get('node');
?>
@ccx105
Copy link

ccx105 commented Dec 5, 2017

Awesome thank you so much for this!

@david-services
Copy link

Usefull, TX

@purushotamrai
Copy link

Use \Drupal::routeMatch()->getParameter('node'); instead

@leymannx
Copy link
Author

@purushotamrai – Why? This won't work on node reviews or node revisions. See https://www.drupal.org/project/drupal/issues/3005029#comment-13180175

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment