Beispiel #1
0
 /**
  * Execute the view's query.
  *
  * @param string $display_id
  *   The machine name of the display, which should be executed.
  *
  * @return bool
  *   Return whether the executing was successful, for example an argument
  *   could stop the process.
  */
 public function execute($display_id = NULL)
 {
     if (empty($this->built)) {
         if (!$this->build($display_id)) {
             return FALSE;
         }
     }
     if (!empty($this->executed)) {
         return TRUE;
     }
     // Don't allow to use deactivated displays, but display them on the live preview.
     if (!$this->display_handler->isEnabled() && empty($this->live_preview)) {
         $this->build_info['fail'] = TRUE;
         return FALSE;
     }
     // Let modules modify the view just prior to executing it.
     $module_handler = \Drupal::moduleHandler();
     $module_handler->invokeAll('views_pre_execute', array($this));
     // Check for already-cached results.
     if (!empty($this->live_preview)) {
         $cache = $this->display_handler->getPlugin('cache', 'none');
     } else {
         $cache = $this->display_handler->getPlugin('cache');
     }
     if ($cache->cacheGet('results')) {
         if ($this->pager->usePager()) {
             $this->pager->total_items = $this->total_rows;
             $this->pager->updatePageInfo();
         }
     } else {
         $this->query->execute($this);
         // Enforce the array key rule as documented in
         // views_plugin_query::execute().
         $this->result = array_values($this->result);
         $this->_postExecute();
         $cache->cacheSet('results');
     }
     // Let modules modify the view just after executing it.
     $module_handler->invokeAll('views_post_execute', array($this));
     $this->executed = TRUE;
 }
Beispiel #2
0
 /**
  * Tests the usePager() method.
  *
  * @see \Drupal\views\Plugin\views\pager\PagerPluginBase::usePager()
  */
 public function testUsePager()
 {
     $this->assertTrue($this->pager->usePager());
 }