How to get the referenced node id in a webform? I have a webform that is connected to a node in drupal 8. When the webform loads from the node link I need to get the source entity id from url.
How can I achieve that in my custom module? the url is as follows:
https://example.com/en/form/edu-form?source_entity_type=node&amp;source_entity_id=134

I tried the following but I get an error:

 $node = \Drupal::routeMatch()-&gt;getParameter('source_entity_id');
 $nodeId = $node-&gt;id();


And also this (I tried to get the node id from the webform object)

/** @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;
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();