Drupal 8 - Retrieve current node

By kenneth, Wed, 09/09/2020 - 11:21
$node = \Drupal::routeMatch()->getParameter('node');
if ($node instanceof \Drupal\node\NodeInterface) {
  $nid = $node->id();
}