nortmas
9/27/2017 - 3:41 PM

Get node from uri

$params = \Drupal\Core\Url::fromUserInput($path)->getRouteParameters();
if (isset($params['node'])) {
  $node = \Drupal\node\Entity\Node::load($params['node']);
}


// or

$node = \Drupal::routeMatch()->getParameter('node');
if ($node) {
  // You can get nid and anything else you need from the node object.
  $nid = $node->id();
}