How to get the referenced node id in a webform?
Make sure that the webform's source entity id can be prepopulated via a URL and the below code should work using $source_entity-&gt;id() instead of $source_entity-&gt;id

/** @var \Drupal\webform\WebformRequestInterface $request_handler */
$request_handler = \Drupal::service('webform.request');
$source_entity = $request_handler-&gt;getCurrentSourceEntity('webform');
$node_id = $source_entity-&gt;id();