By timmillwood on
Change record status:
Published (View all published change records)
Project:
Introduced in branch:
8.6.x
Introduced in version:
8.6.0-alpha1
Issue links:
Description:
Two new traits have been added to assist with AJAX requests:
AjaxHelperTrait
This trait defines two methods:
isAjax()- Returning a boolean value,isAjax()does exactly what it says. It determines if the current request is via AJAX. Then returnsTRUEif the current request is via AJAX,FALSEotherwise.getRequestFormat()- Returning a string value, this method gets the wrapper format of the current request.
AjaxFormHelperTrait
To be used when submitting a form via AJAX this trait containts a public method and an abstract protected method:
ajaxSubmit($form, $form_state)- This should be set as the AJAX callback on the submit button. It will flag any errors, and on a successful submission call the other method in this trait,successfulAjaxSubmit().successfulAjaxSubmit($form, $form_sate)- This abstract method would need to be implemented in the class which uses the trait, it's where the successful AJAX submission is responded to. It must return a\Drupal\Core\Ajax\AjaxResponseobject.
Impacts:
Module developers