You are here

class ViewsAjaxController in Views Ajax Get 8

Same name and namespace in other branches
  1. 2.0.x src/Controller/ViewsAjaxController.php \Drupal\views_ajax_get\Controller\ViewsAjaxController

Controller that allows for Views AJAX GET requests that can be cached.

Hierarchy

Expanded class hierarchy of ViewsAjaxController

File

src/Controller/ViewsAjaxController.php, line 13

Namespace

Drupal\views_ajax_get\Controller
View source
class ViewsAjaxController extends ViewAjaxController {

  /**
   * {@inheritdoc}
   */
  public function ajaxView(Request $request) {
    if ($request
      ->getMethod() !== Request::METHOD_GET) {
      return parent::ajaxView($request);
    }

    // Add all query parameters to the post variable, because this is what
    // \Drupal\views\Controller\ViewAjaxController::ajaxView expects.
    $request->request
      ->add($request->query
      ->all());
    $response = parent::ajaxView($request);
    $view = $response
      ->getView();
    if (_views_ajax_get_is_ajax_get_view($view)) {
      $cacheable_response = new CacheableViewsAjaxResponse();
      $cacheable_response
        ->setView($view);
      $cacheable_commands =& $cacheable_response
        ->getCommands();
      $cacheable_commands = $response
        ->getCommands();
      $view_metadata = CacheableMetadata::createFromRenderArray($view->element);
      $metadata = $cacheable_response
        ->getCacheableMetadata();
      $metadata
        ->addCacheableDependency($view_metadata);

      // Don't allow attachments
      // $cacheable_response->setAttachments($response->getAttachments());
      return $cacheable_response;
    }
    return $response;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ViewAjaxController::$currentPath protected property The current path.
ViewAjaxController::$executableFactory protected property The factory to load a view executable with.
ViewAjaxController::$redirectDestination protected property The redirect destination.
ViewAjaxController::$renderer protected property The renderer.
ViewAjaxController::$storage protected property The entity storage for views.
ViewAjaxController::create public static function Instantiates a new instance of this class. Overrides ContainerInjectionInterface::create
ViewAjaxController::__construct public function Constructs a ViewAjaxController object.
ViewsAjaxController::ajaxView public function Loads and renders a view via AJAX. Overrides ViewAjaxController::ajaxView