In Drupal\rsvplist\Form\RSVPForm->buildForm(), I wrote this to get the current nid:
$node = \Drupal::routeMatch()->getParameter('node');
$nid = $node->nid->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?
id()
method instead. You also have to check if $node is an instance of NodeInterface because you could be on a route where that won't work (like a user, view, taxonomy, or media route).