PagerSelectExtender::execute

public PagerSelectExtender::execute()

Override the execute method.

Before we run the query, we need to add pager-based range() instructions to it.

Overrides SelectExtender::execute

File

core/lib/Drupal/Core/Database/Query/PagerSelectExtender.php, line 61

Class

PagerSelectExtender
Query extender for pager queries.

Namespace

Drupal\Core\Database\Query

Code

public function execute() {
  // By calling preExecute() here, we force it to preprocess the extender
  // object rather than just the base query object. That means
  // hook_query_alter() gets access to the extended object.
  if (!$this->preExecute($this)) {
    return NULL;
  }

  // A NULL limit is the "kill switch" for pager queries.
  if (empty($this->limit)) {
    return;
  }
  $this->ensureElement();

  $total_items = $this->getCountQuery()->execute()->fetchField();
  $current_page = pager_default_initialize($total_items, $this->limit, $this->element);
  $this->range($current_page * $this->limit, $this->limit);

  // Now that we've added our pager-based range instructions, run the query normally.
  return $this->query->execute();
}
doc_Drupal
2016-10-29 09:33:02
Comments
Leave a Comment

Please login to continue.