You are here

public function PollViewForm::ajaxReplaceForm in Poll 8

Ajax callback to replace the poll form.

File

src/Form/PollViewForm.php, line 121

Class

PollViewForm
Displays banned IP addresses.

Namespace

Drupal\poll\Form

Code

public function ajaxReplaceForm(array $form, FormStateInterface $form_state) {

  // Embed status message into the form.
  $form = [
    'messages' => [
      '#type' => 'status_messages',
    ],
  ] + $form;

  /** @var \Drupal\Core\Render\RendererInterface $renderer */
  $renderer = \Drupal::service('renderer');

  // Render the form.
  $output = $renderer
    ->renderRoot($form);
  $response = new AjaxResponse();
  $response
    ->setAttachments($form['#attached']);

  // Replace the form completely and return it.
  return $response
    ->addCommand(new ReplaceCommand('.poll-view-form-' . $this->poll
    ->id(), $output));
}