You are here

protected function WebformEntityAjaxFormTrait::replaceForm in Webform 6.x

Same name and namespace in other branches
  1. 8.5 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 for webform entity 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 WebformHtmlCommand('#' . $this
    ->getWrapperId(), $form));
  return $response;
}