Unable to programmatically render webform with supplied default values I have a block that is rendering a webform programmatically however I want to change a field based on the node that it's appearing on. I'm performing this like so.

    $webform_id = 'contact';
    $current_node = \Drupal::routeMatch()-&gt;getParameter('node');
    $contact_form = \Drupal\webform\Entity\Webform::load($webform_id);
    $values = ['data' =&gt; ['contact_email' =&gt; $current_node-&gt;field_email-&gt;value, 'message' =&gt; 'test']];
    $contact_form-&gt;getSubmissionForm($values);
    $contact_form_render = \Drupal::entityManager()
        -&gt;getViewBuilder('webform')
        -&gt;view($contact_form);
    return $contact_form_render;


It is able to render the webform just fine, however the supplied values for the contact_email field and the message field do not appear, even though they were supplied as a parameter for getSubmissionForm. I've used https://www.drupal.org/docs/8/modules/webform/webform-cookbook/how-to-embed-a-webform as an example but I don't seem to see any discrepancies between my code and theirs.

Is there something wrong with how I'm supplying the values to the programmatically rendered webform?

UPDATE: I tried doing things in a more manual manner

$form_storage = \Drupal::entityTypeManager()-&gt;getStorage('webform');
$webform_submission = $form_storage
      -&gt;create(['webform_id'=&gt;'contact', 'data' =&gt; ['contact_email' =&gt; $current_node-&gt;field_email-&gt;value],'message' =&gt; 'testing']);

$contact_form_render = \Drupal::entityManager()
      -&gt;getViewBuilder('webform')
      -&gt;view($webform_submission);


However I get the error


  Exception: Webform id (webform_id) is required to create a webform
  submission. in Drupal\webform\Entity\WebformSubmission::preCreate()
  (line 586 of
  modules/contrib/webform/src/Entity/WebformSubmission.php).


Even though I'm explicitly setting the webform_id.
Did you try using the Webform render element documented at the bottom of https://www.drupal.org/docs/8/modules/webform/webform-cookbook/how-to-embed-a-webform.

return [
  '#type' =&gt; 'webform',
  '#webform' =&gt; 'your_form_id',
  '#default_data' =&gt; ['name' =&gt; 'Custom Name'],
];