How do I get the associated node from a webform entity? I'm preprocessing a webform using hook_webform_submission_form_alter. The webform is being rendered as a node field. How can I, from inside my form_alter hook access that node? 

function MY_MODULE_webform_submission_form_alter(array &amp;$form, FormStateInterface $form_state, $form_id) {
    $parameters = \Drupal::routeMatch()-&gt;getParameters();

    if ($parameters-&gt;has('node')) {

        // processing goes here
    }
}


I'm fetching it from the url parameter right now, but I would prefer to do this in a cleaner way.
After some digging, I've found out the answer.

This is how I get the webform submission, the webform object, and the associated node:

    function MY_MODULE_webform_submission_form_alter(array &amp;$form, FormStateInterface $form_state, $form_id) {

        $entity  = $form_state-&gt;getFormObject()-&gt;getEntity(); // webform submission
        $webform = $form_state-&gt;getFormObject()-&gt;getWebform(); // webform object
        $node    = $entity-&gt;getSourceEntity(); // associated node

        // (...)
    }