trait AjaxFormHelperTrait in Drupal 9
Same name and namespace in other branches
- 8 core/lib/Drupal/Core/Ajax/AjaxFormHelperTrait.php \Drupal\Core\Ajax\AjaxFormHelperTrait
- 10 core/lib/Drupal/Core/Ajax/AjaxFormHelperTrait.php \Drupal\Core\Ajax\AjaxFormHelperTrait
Provides a helper to for submitting an AJAX form.
@internal
Hierarchy
- trait \Drupal\Core\Ajax\AjaxFormHelperTrait uses AjaxHelperTrait
5 files declare their use of AjaxFormHelperTrait
- BlockEntitySettingTrayForm.php in core/
modules/ settings_tray/ src/ Block/ BlockEntitySettingTrayForm.php - ConfigureBlockFormBase.php in core/
modules/ layout_builder/ src/ Form/ ConfigureBlockFormBase.php - ConfigureSectionForm.php in core/
modules/ layout_builder/ src/ Form/ ConfigureSectionForm.php - LayoutRebuildConfirmFormBase.php in core/
modules/ layout_builder/ src/ Form/ LayoutRebuildConfirmFormBase.php - MoveBlockForm.php in core/
modules/ layout_builder/ src/ Form/ MoveBlockForm.php
File
- core/
lib/ Drupal/ Core/ Ajax/ AjaxFormHelperTrait.php, line 12
Namespace
Drupal\Core\AjaxView source
trait AjaxFormHelperTrait {
use AjaxHelperTrait;
/**
* Submit form dialog #ajax callback.
*
* @param array $form
* An associative array containing the structure of the form.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The current state of the form.
*
* @return \Drupal\Core\Ajax\AjaxResponse
* An AJAX response that display validation error messages or represents a
* successful submission.
*/
public function ajaxSubmit(array &$form, FormStateInterface $form_state) {
if ($form_state
->hasAnyErrors()) {
$form['status_messages'] = [
'#type' => 'status_messages',
'#weight' => -1000,
];
$form['#sorted'] = FALSE;
$response = new AjaxResponse();
$response
->addCommand(new ReplaceCommand('[data-drupal-selector="' . $form['#attributes']['data-drupal-selector'] . '"]', $form));
}
else {
$response = $this
->successfulAjaxSubmit($form, $form_state);
}
return $response;
}
/**
* Allows the form to respond to a successful AJAX submission.
*
* @param array $form
* An associative array containing the structure of the form.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The current state of the form.
*
* @return \Drupal\Core\Ajax\AjaxResponse
* An AJAX response.
*/
protected abstract function successfulAjaxSubmit(array $form, FormStateInterface $form_state);
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AjaxFormHelperTrait:: |
public | function | Submit form dialog #ajax callback. | |
AjaxFormHelperTrait:: |
abstract protected | function | Allows the form to respond to a successful AJAX submission. | 5 |
AjaxHelperTrait:: |
protected | function | Gets the wrapper format of the current request. | |
AjaxHelperTrait:: |
protected | function | Determines if the current request is via AJAX. |