You are here

public function AjaxFormTrait::ajaxModalCallback in Forena Reports 8

Ajax callback.

_state

Parameters

$form:

Return value

\Drupal\Core\Ajax\AjaxResponse

1 call to AjaxFormTrait::ajaxModalCallback()
AjaxFormTrait::submitCallback in src/Form/AjaxFormTrait.php
Ajax callback handler for submit buttons.

File

src/Form/AjaxFormTrait.php, line 94

Class

AjaxFormTrait
Class AjaxFormTrait

Namespace

Drupal\forena\Form

Code

public function ajaxModalCallback(&$form, FormStateInterface $form_state) {
  if ($form_state
    ->getErrors() || $form_state
    ->isRebuilding()) {
    unset($form['#prefix']);
    unset($form['#suffix']);

    // array merge the status elements onto the beginning of the form
    $ctl['status_messages'] = [
      '#type' => 'status_messages',
      '#weight' => -10,
    ];
    $form = array_merge($ctl, $form);
    $this->controller
      ->setEndCommand(new HtmlCommand('#e-modal-form', $form));
  }
  else {
    $this->controller
      ->setEndCommand(new CloseDialogCommand());
  }
  $commands = $this->controller
    ->getCommands();
  $response = new AjaxResponse();
  foreach ($commands as $command) {
    $response
      ->addCommand($command);
  }
  $this->controller
    ->saveState();
  return $response;
}