You are here

public function GroupEditForm::submitFormAjax in Context groups 8

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

Handle when the form is submitted through AJAX.

Return value

AjaxResponse AjaxResponce object.

File

src/Form/GroupEditForm.php, line 122

Class

GroupEditForm
Class GroupEditForm.

Namespace

Drupal\context_groups\Form

Code

public function submitFormAjax(&$form, FormStateInterface $form_state) {
  $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-edit-form"]', $output));
  }
  else {
    $response
      ->addCommand(new CloseModalDialogCommand());
    $contextForm = $this->contextManager
      ->getForm($this->context, 'edit');
    $response
      ->addCommand(new ReplaceCommand('#context-reactions', $contextForm['reactions']));
  }
  return $response;
}