Esempio n. 1
0
 /**
  * {@inheritdoc}
  */
 public function cacheGet($type)
 {
     if ($type != 'results') {
         return parent::cacheGet($type);
     }
     // Values to set: $view->result, $view->total_rows, $view->execute_time,
     // $view->current_page.
     if ($cache = \Drupal::cache($this->resultsBin)->get($this->generateResultsKey())) {
         $cutoff = $this->cacheExpire($type);
         if (!$cutoff || $cache->created > $cutoff) {
             $this->view->result = $cache->data['result'];
             $this->view->total_rows = $cache->data['total_rows'];
             $this->view->setCurrentPage($cache->data['current_page']);
             $this->view->execute_time = 0;
             // Trick Search API into believing a search happened, to make faceting
             // et al. work.
             /** @var \Drupal\search_api\Query\ResultSetInterface $results */
             $results = $cache->data['search_api results'];
             /** @var \Drupal\search_api\Query\ResultsCacheInterface $static_results_cache */
             $static_results_cache = \Drupal::service('search_api.results_static_cache');
             $static_results_cache->addResults($results);
             try {
                 $this->getQuery()->setSearchApiResults($results);
                 $this->getQuery()->setSearchApiQuery($results->getQuery());
             } catch (SearchApiException $e) {
                 // Ignore.
             }
             return TRUE;
         }
     }
     return FALSE;
 }
 /**
  * {@inheritdoc}
  */
 public function cacheGet($type)
 {
     if ($type != 'results') {
         return parent::cacheGet($type);
     }
     // Values to set: $view->result, $view->total_rows, $view->execute_time,
     // $view->current_page.
     if ($cache = \Drupal::cache($this->resultsBin)->get($this->generateResultsKey())) {
         $cutoff = $this->cacheExpire($type);
         if (!$cutoff || $cache->created > $cutoff) {
             $this->view->result = $cache->data['result'];
             $this->view->total_rows = $cache->data['total_rows'];
             $this->view->setCurrentPage($cache->data['current_page']);
             $this->view->execute_time = 0;
             // Trick Search API into believing a search happened, to make facetting
             // et al. work.
             $query = $this->getQuery()->getSearchApiQuery();
             // @todo Find a replacement for that. Also set it on the Views Query?
             search_api_current_search($query->getOption('search id'), $query, $cache->data['search_api results']);
             return TRUE;
         }
     }
     return FALSE;
 }