Currently, there is no way for a custom module to alter the AjaxResponse before being sent on webforms with Ajax enabled.

It would be great to have available a hook to be able to add or alter the commands that are to be sent.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

imadalin created an issue. See original summary.

jrockowitz’s picture

The solution is going to be to create a WebformViewResponse object which can be altered via an event subscriber.

@see https://www.linkedin.com/pulse/how-alter-ajax-commands-view-response-dru...

  • jrockowitz committed b33134e on 2911409-ajax-response
    Issue #2911409: Allow AjaxResponse to be altered before it's sent
    

  • jrockowitz committed cb3f62b on 2911409-ajax-response
    Issue #2911409: Allow AjaxResponse to be altered before it's sent
    
jrockowitz’s picture

Status: Active » Needs review
FileSize
6.88 KB

The attached patch contains WebformSubmissionAjaxResponse object which is returned by all WebformSubmissionForm ajax responses.

Please note: Drupal is moving away from alter hooks and EventSubscribers are the recommended way to alter a request and/or a response.

  • jrockowitz committed 222fa0c on 8.x-5.x
    Issue #2911409 by jrockowitz: Allow AjaxResponse to be altered before it...
jrockowitz’s picture

Status: Needs review » Fixed

I committed the patch. Please download the latest dev release to review.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.