protected function WebformEntityAjaxFormTrait::replaceForm in Webform 8.5
Same name and namespace in other branches
- 6.x src/Form/WebformEntityAjaxFormTrait.php \Drupal\webform\Form\WebformEntityAjaxFormTrait::replaceForm()
Replace form via an Ajax response.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Return value
\Drupal\Core\Ajax\AjaxResponse An Ajax response that replaces a form.
Overrides WebformAjaxFormTrait::replaceForm
1 call to WebformEntityAjaxFormTrait::replaceForm()
- WebformEntityAjaxFormTrait::cancelAjaxForm in src/
Form/ WebformEntityAjaxFormTrait.php - Cancel form #ajax callback.
File
- src/
Form/ WebformEntityAjaxFormTrait.php, line 47
Class
- WebformEntityAjaxFormTrait
- Trait class for Webform Ajax support.
Namespace
Drupal\webform\FormCode
protected function replaceForm(array $form, FormStateInterface $form_state) {
// Display messages first by prefixing it the form and setting its weight
// to -1000.
$form = [
'status_messages' => [
'#type' => 'status_messages',
'#weight' => -1000,
],
] + $form;
// Remove wrapper.
unset($form['#prefix'], $form['#suffix']);
$response = $this
->createAjaxResponse($form, $form_state);
$response
->addCommand(new WebformHtmlCommand('#' . $this
->getWrapperId(), $form));
return $response;
}