You are here

protected function WebformAjaxFormTrait::replaceForm in Webform 8.5

Same name and namespace in other branches
  1. 6.x src/Form/WebformAjaxFormTrait.php \Drupal\webform\Form\WebformAjaxFormTrait::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.

1 call to WebformAjaxFormTrait::replaceForm()
WebformAjaxFormTrait::submitAjaxForm in src/Form/WebformAjaxFormTrait.php
Submit form #ajax callback.
1 method overrides WebformAjaxFormTrait::replaceForm()
WebformEntityAjaxFormTrait::replaceForm in src/Form/WebformEntityAjaxFormTrait.php
Replace form via an Ajax response.

File

src/Form/WebformAjaxFormTrait.php, line 334

Class

WebformAjaxFormTrait
Trait class for Webform Ajax support.

Namespace

Drupal\webform\Form

Code

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 HtmlCommand('#' . $this
    ->getWrapperId(), $form));
  return $response;
}