You are here

public static function EntityReferenceActionsHandler::dialogAjaxSubmit in Entity reference actions 1.x

Submit form dialog #ajax callback.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

\Drupal\Core\Ajax\AjaxResponse An AJAX response that display validation error messages or represents a successful submission.

File

src/EntityReferenceActionsHandler.php, line 507

Class

EntityReferenceActionsHandler
Provides the form functions to call actions on referenced entities.

Namespace

Drupal\entity_reference_actions

Code

public static function dialogAjaxSubmit(array &$form, FormStateInterface $form_state) {
  $response = new AjaxResponse();
  if ($form_state
    ->hasAnyErrors()) {
    $form['status_messages'] = [
      '#type' => 'status_messages',
      '#weight' => -1000,
    ];
    $form['#sorted'] = FALSE;
    $response
      ->addCommand(new ReplaceCommand('[data-drupal-selector="' . $form['#attributes']['data-drupal-selector'] . '"]', $form));
  }
  else {
    $response
      ->addCommand(new MessageCommand(t('Action was successfully applied.'), '[data-entity-reference-actions-messages]'));
    $response
      ->addCommand(new CloseModalDialogCommand());
  }
  return $response;
}