How to autofill webform with node field data I have a content type, applicant with a name, and birthday field. I also have a entity reference to a webform, which has a name and birthday fields, as well as others. I want to allow users to create the applicant content type, then click the link to webform, and autofill the appropriate fields on the webform. 

I've been trying to use the FormStateInterface::setValue method. Here' where I am so far:

function mymodule_webform_element_alter(array &amp;$element, \Drupal\Core\Form\FormStateInterface $form_state, array $context) {
  kint($element); // this outputs '#webform_key' =&gt; string(4) "name"

  $form_state-&gt;setValue('name', 'bob'); // Here I'm just trying to statically set the field.
}


This method doesn't actually autofill, and it also doesn't actually set the value. This is a demo-project, so we don't have specs yet, so I'm actually fine with either auto-filling, or setting the value, probably both.

The main thing I'm trying to do here is to link one node entity to a webform submission.
Using hook_form_alter() or hook_form_FORM_ID_alter(), you can set the default value by php code

For Example

function HOOK_form_FORM_ID_alter(&amp;$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id){
  if($form_id == 'YOUR_FROM_ID'){
    $form['submitted']['FIELDNAME']['#default_value'] = date("Y-m-d h:i a", time());
  }
}