You are here

public function AjaxFormBase::ajaxCallback in Forena Reports 8

Ajax callback.

Parameters

AjaxPageControllerBase $controller: The controller to register with the interface

array $form: Drupal form render array

$form_state: Drupral form state object.

Return value

\Drupal\Core\Ajax\AjaxResponse

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

File

src/Form/AjaxFormBase.php, line 87

Class

AjaxFormBase
Class AjaxFormTrait

Namespace

Drupal\forena\Form

Code

public function ajaxCallback($form, FormStateInterface $form_state) {
  $response = new AjaxResponse();

  // Make sure form error rebuilds happen.
  if ($form_state
    ->getErrors() || $form_state
    ->isRebuilding()) {
    $ctl['status_messages'] = [
      '#type' => 'status_messages',
      '#weight' => -10,
    ];

    // Array merge the status element onto the beginning of the form.
    $form = array_merge($ctl, $form);
    $section = $form_state
      ->get('e_section');
    $command = new HtmlCommand("#{$section}", $form);
    $response
      ->addCommand($command);
    $this->controller->section = $this->controller->prior_section;
  }
  else {
    $this->controller->section = $this->controller->prior_section;
    if (!$this->controller->prevent_action) {
      $this->controller->post_form_id = $form_state
        ->getFormObject()
        ->getFormId();
      $this->controller
        ->route($this->controller->action);
    }
  }
  $commands = $this->controller
    ->getCommands();
  foreach ($commands as $command) {
    $response
      ->addCommand($command);
  }
  $this->controller
    ->saveState();
  return $response;
}