You are here

public function DisclaimerEmailMatchForm::ajaxSubmit in Disclaimer 8

File

src/Form/DisclaimerEmailMatchForm.php, line 155

Class

DisclaimerEmailMatchForm
Class DisclaimerEmailMatchForm.

Namespace

Drupal\disclaimer\Form

Code

public function ajaxSubmit(array &$form, FormStateInterface $form_state) {
  $status_messages = [
    '#type' => 'status_messages',
  ];
  if ($form_state
    ->hasAnyErrors()) {

    // Show form with errors.
    $form['#prefix'] .= $this->renderer
      ->renderRoot($status_messages);
    return $form;
  }
  else {

    // All good. Return command to close the UI dialog.
    $response = new AjaxResponse();
    $response
      ->addCommand(new InvokeCommand('.disclaimer_email__challenge', 'dialog', [
      'close',
    ]));
    return $response;
  }
}