You are here

public function SqlBase::setCurrentPage in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/views/src/Plugin/views/pager/SqlBase.php \Drupal\views\Plugin\views\pager\SqlBase::setCurrentPage()

Set the current page.

Parameters

$number: If provided, the page number will be set to this. If NOT provided, the page number will be set from the global page array.

Overrides PagerPluginBase::setCurrentPage

1 call to SqlBase::setCurrentPage()
SqlBase::updatePageInfo in core/modules/views/src/Plugin/views/pager/SqlBase.php
Update global paging info.

File

core/modules/views/src/Plugin/views/pager/SqlBase.php, line 250
Contains \Drupal\views\Plugin\views\pager\SqlBase.

Class

SqlBase
A common base class for sql based pager.

Namespace

Drupal\views\Plugin\views\pager

Code

public function setCurrentPage($number = NULL) {
  if (isset($number)) {
    $this->current_page = max(0, $number);
    return;
  }

  // If the current page number was not specified, extract it from the global
  // page array.
  global $pager_page_array;
  if (empty($pager_page_array)) {
    $pager_page_array = array();
  }

  // Fill in missing values in the global page array, in case the global page
  // array hasn't been initialized before.
  $page = $this->view
    ->getRequest()->query
    ->get('page');
  $page = isset($page) ? explode(',', $page) : array();
  for ($i = 0; $i <= $this->options['id'] || $i < count($pager_page_array); $i++) {
    $pager_page_array[$i] = empty($page[$i]) ? 0 : $page[$i];
  }

  // Don't allow the number to be less than zero.
  $this->current_page = max(0, intval($pager_page_array[$this->options['id']]));
}