You are here

public function GroupAddForm::submitFormAjax in Context groups 8

Same name and namespace in other branches
  1. 8.2 src/Form/GroupAddForm.php \Drupal\context_groups\Form\GroupAddForm::submitFormAjax()

Handle when the form is submitted through AJAX.

Return value

AjaxResponse Return AjaxResponse object.

File

src/Form/GroupAddForm.php, line 154

Class

GroupAddForm
Class GroupDeleteForm.

Namespace

Drupal\context_groups\Form

Code

public function submitFormAjax(&$form, FormStateInterface $form_state) {
  $contextForm = $this->contextManager
    ->getForm($this->context, 'edit');
  $response = new AjaxResponse();
  if ($form_state
    ->getErrors()) {
    $output[] = StatusMessages::renderMessages(NULL);
    $output[] = $form;

    // Ajax commands.
    $response
      ->addCommand(new RemoveCommand('.messages.messages--error'));
    $response
      ->addCommand(new ReplaceCommand('[id^="context-group-add-group"]', $output));
  }
  else {
    $response
      ->addCommand(new CloseModalDialogCommand());
    $response
      ->addCommand(new ReplaceCommand('#context-reactions', $contextForm['reactions']));
  }
  return $response;
}