You are here

public function AjaxFormTrait::ajaxCallback in Forena Reports 8

Ajax callback.

Parameters

array $form: Drupal form render array

$form_state: Drupral form state object.

Return value

\Drupal\Core\Ajax\AjaxResponse

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

File

src/Form/AjaxFormTrait.php, line 62

Class

AjaxFormTrait
Class AjaxFormTrait

Namespace

Drupal\forena\Form

Code

public function ajaxCallback($form, FormStateInterface $form_state) {
  $commands = $this->controller
    ->getCommands();
  $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);
  }
  foreach ($commands as $command) {
    $response
      ->addCommand($command);
  }
  $this->controller
    ->saveState();
  return $response;
}