You are here

public function Full::query in Views (for Drupal 7) 8.3

Modify the query for paging

This is called during the build phase and can directly modify the query.

Overrides PagerPluginBase::query

File

lib/Drupal/views/Plugin/views/pager/Full.php, line 261
Definition of Drupal\views\Plugin\views\pager\Full.

Class

Full
The plugin to handle full pager.

Namespace

Drupal\views\Plugin\views\pager

Code

public function query() {
  if ($this
    ->items_per_page_exposed()) {
    $query = drupal_container()
      ->get('request')->query;
    $items_per_page = $query
      ->get('items_per_page');
    if ($items_per_page > 0) {
      $this->options['items_per_page'] = $items_per_page;
    }
    elseif ($items_per_page == 'All' && $this->options['expose']['items_per_page_options_all']) {
      $this->options['items_per_page'] = 0;
    }
  }
  if ($this
    ->offset_exposed()) {
    $query = drupal_container()
      ->get('request')->query;
    $offset = $query
      ->get('offset');
    if (isset($offset) && $offset >= 0) {
      $this->options['offset'] = $offset;
    }
  }
  $limit = $this->options['items_per_page'];
  $offset = $this->current_page * $this->options['items_per_page'] + $this->options['offset'];
  if (!empty($this->options['total_pages'])) {
    if ($this->current_page >= $this->options['total_pages']) {
      $limit = $this->options['items_per_page'];
      $offset = $this->options['total_pages'] * $this->options['items_per_page'];
    }
  }
  $this->view->query
    ->set_limit($limit);
  $this->view->query
    ->set_offset($offset);
}