You are here

public function CacheableViewsAjaxResponse::unserialize in Views Ajax Get 2.0.x

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

File

src/CacheableViewsAjaxResponse.php, line 30

Class

CacheableViewsAjaxResponse

Namespace

Drupal\views_ajax_get

Code

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();
  }
}