Close webform modal and redirect to entity I have a webform that opens inside a modal. Everything works fine. Then I had the problem of closing the modal after the form was submitted. I fixed that to with the help of the following link: https://www.drupal.org/project/webform/issues/3002966#comment-12794056

I have a webform handler that creates a new entity in the postSave() method. After this entity is created, I want to close the modal and redirect to the entity detail page. What is the best/correct way to do this. I could use a RedirectCommand instead of the CloseDialogCommand but how do I get the entity id in the _CUSTOM_MODULE_webform_submission_form_submit_ajax() method. Using the AjaxResponse with a RedirectCommand in the postSave() method didn't work.

Any Suggestions would be great ;-)
Yes you are so close!
just move the creation of the new entity from your postSave()
to right in the ajax call back

example:

_CUSTOM_MODULE_webform_submission_form_submit_ajax(array &amp;$form, FormStateInterface $form_state) {
 // At this point we have all access to $form_state-&gt;getValues();
 // the webform submission is all ready saved so we can use the values here.

 // Get the entity storage.
 $entity_storage = \Drupal::entityTypeManager()-&gt;getStoage('ENITYNAME');

  // Create New entity.
  $new_entity = $entity_storage-&gt;create([
   'field_whatever' =&gt; $form_state-&gt;getValue('some_field');
  ]);
  // Save entity
  $new_entity-&gt;save();
  $new_entity_id = $new_entity-&gt;id();
  // set the url. 
  $url = "/where-ever/" . $new_entity_id;

  $response = new AjaxResponse();
  $response-&gt;addCommand(new CloseModalDialogCommand());
  $response-&gt;addCommand(new RedirectCommand($url);
  // Party.
 return $response;
}