You are here

public function AjaxPageControllerBase::response in Forena Reports 8

Return the response based on ajax pramters.

Parameters

string $action: The action used by the reout to generate a reponse.

Return value

array | null Drupal render array containing action.

Overrides AjaxControllerInterface::response

1 call to AjaxPageControllerBase::response()
AjaxPageControllerBase::page in src/Controller/AjaxPageControllerBase.php
Default page controller implementation. This method is typically what you would reference in the routing.yml file as the main menu callback for the controller.

File

src/Controller/AjaxPageControllerBase.php, line 275

Class

AjaxPageControllerBase

Namespace

Drupal\forena\Controller

Code

public function response($action) {
  $this->action = $action;
  switch ($this->jsMode) {
    case 'nojs':
      $this
        ->initLayout();
      $this
        ->processFormRequest();
      if (!$this->prevent_action) {
        $this
          ->route($action);
      }
      foreach ($this->build as $section => $content) {
        if (is_array($content)) {
          $content = \Drupal::Service('renderer')
            ->render($content);
        }
        $this->context->{$section} = $content;
      }
      $content = Forena::service()
        ->report($this->layout);

      // Add the ajax librarries used by teh controller.
      if (!empty($content['#attached']['library'])) {
        $content['#attached']['library'] = array_merge($content['#attached']['library'], $this->libraries);
      }
      else {
        $content['#attached']['library'] = $this->libraries;
      }
      $response = $content;
      break;
    case 'drupal_modal':

      // This is the type sent when you use the "data-dialog-type" class.
      // Note that it is not the common way to display a modal.
      $this
        ->processFormRequest();
      if (!$this->prevent_action) {
        $this
          ->route($action);
      }
      $response = $this->build;
      break;
    default:

      // All other types are assumed to be some ajax variant.
      $this
        ->processFormRequest();
      if (!$this->prevent_action) {
        $this
          ->route($action);
      }
      $commands = $this
        ->getCommands();

      //print ajax_render($commands);
      $response = new AjaxResponse();
      foreach ($commands as $command) {
        $response
          ->addCommand($command);
      }
  }
  $this
    ->saveState();
  return $response;
}