hasAnyErrors()) { $form['status_messages'] = [ '#type' => 'status_messages', '#weight' => -1000, ]; $response = new AjaxResponse(); $response->addCommand(new ReplaceCommand('[data-drupal-selector="' . $form['#attributes']['data-drupal-selector'] . '"]', $form)); } else { $response = $this->successfulAjaxSubmit($form, $form_state); } return $response; } /** * Allows the form to respond to a successful AJAX submission. * * @param array $form * An associative array containing the structure of the form. * @param \Drupal\Core\Form\FormStateInterface $form_state * The current state of the form. * * @return \Drupal\Core\Ajax\AjaxResponse * An AJAX response. */ abstract protected function successfulAjaxSubmit(array $form, FormStateInterface $form_state); }