You are here

class CacheableViewsAjaxResponse in Views Ajax Get 2.0.x

Same name and namespace in other branches
  1. 8 src/CacheableViewsAjaxResponse.php \Drupal\views_ajax_get\CacheableViewsAjaxResponse

Hierarchy

Expanded class hierarchy of CacheableViewsAjaxResponse

1 file declares its use of CacheableViewsAjaxResponse
ViewsAjaxController.php in src/Controller/ViewsAjaxController.php

File

src/CacheableViewsAjaxResponse.php, line 11

Namespace

Drupal\views_ajax_get
View source
class CacheableViewsAjaxResponse extends ViewAjaxResponse implements CacheableResponseInterface, \Serializable {
  use CacheableResponseTrait;

  /**
   * {@inheritdoc}
   */
  public function serialize() {
    $vars = get_object_vars($this);
    unset($vars['view']);
    $vars['view_id'] = $this->view
      ->id();
    $vars['display_id'] = $this->view->current_display;
    return serialize($vars);
  }

  /**
   * {@inheritdoc}
   */
  public function unserialize($serialized) {
    $unserialized = unserialize($serialized);
    foreach ($unserialized as $key => $value) {
      $this->{$key} = $value;
    }

    // Ensure that there is a request on the request stack.
    $fake_request = FALSE;
    if (!($request = \Drupal::request())) {
      $fake_request = TRUE;
      \Drupal::requestStack()
        ->push(Request::create('/uri'));
    }
    $this->view = Views::getView($unserialized['view_id']);
    $this->view
      ->setDisplay($unserialized['display_id']);
    if ($fake_request) {
      \Drupal::requestStack()
        ->pop();
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AjaxResponse::$commands protected property The array of ajax commands.
AjaxResponse::addCommand public function Add an AJAX command to the response.
AjaxResponse::getCommands public function Gets all AJAX commands.
AttachmentsTrait::$attachments protected property The attachments for this response.
AttachmentsTrait::addAttachments public function
AttachmentsTrait::getAttachments public function
AttachmentsTrait::setAttachments public function
CacheableResponseTrait::$cacheabilityMetadata protected property The cacheability metadata.
CacheableResponseTrait::addCacheableDependency public function
CacheableResponseTrait::getCacheableMetadata public function
CacheableViewsAjaxResponse::serialize public function
CacheableViewsAjaxResponse::unserialize public function
ViewAjaxResponse::$view protected property The view executed on this ajax request.
ViewAjaxResponse::getView public function Gets the executed view of this response.
ViewAjaxResponse::setView public function Sets the executed view of this response.