Notice: Trying to get property 'nid' of non-object In Drupal\rsvplist\Form\RSVPForm->buildForm(), I wrote this to get the current nid:

$node = \Drupal::routeMatch()-&gt;getParameter('node');
$nid = $node-&gt;nid-&gt;value;


I get this error:


  Notice: Trying to get property 'nid' of non-object in
  Drupal\rsvplist\Form\RSVPForm->buildForm() (line 30 of
  modules\custom\rsvplist\src\Form\RSVPForm.php).


I am a new module developer. How to get the current nid in drupal 8?
You will need to check if the $node variable is actually an instance of node object.

if ($node instanceof \Drupal\node\NodeInterface) {
  // You can get nid and anything else you need from the node object.
  $nid = $node-&gt;id();
}


See

How do I get the current node ID?