PagerManager.php in Drupal 8
File
core/lib/Drupal/Core/Pager/PagerManager.php
View source
<?php
namespace Drupal\Core\Pager;
use Drupal\Component\Utility\DeprecatedArray;
use Drupal\Core\DependencyInjection\DependencySerializationTrait;
class PagerManager implements PagerManagerInterface {
use DependencySerializationTrait;
protected $pagerParams;
protected $pagers;
public function __construct(PagerParametersInterface $pager_params) {
$this->pagerParams = $pager_params;
}
public function createPager($total, $limit, $element = 0) {
$currentPage = $this->pagerParams
->findPage($element);
$pager = new Pager($total, $limit, $currentPage);
$this
->setPager($pager, $element);
return $pager;
}
public function getPager($element = 0) {
return isset($this->pagers[$element]) ? $this->pagers[$element] : NULL;
}
public function getUpdatedParameters(array $query, $element, $index) {
$element_pages = [];
$max = $this
->getMaxPagerElementId();
for ($i = 0; $i <= $max; $i++) {
$currentPage = ($pager = $this
->getPager($i)) ? $pager
->getCurrentPage() : NULL;
$element_pages[] = $i == $element ? $index : $currentPage;
}
$query['page'] = implode(',', $element_pages);
if ($current_query = $this->pagerParams
->getQueryParameters()) {
$query = array_merge($current_query, $query);
}
return $query;
}
protected function getMaxPagerElementId() {
return empty($this->pagers) ? -1 : max(array_keys($this->pagers));
}
protected function setPager(Pager $pager, $element = 0) {
$this->pagers[$element] = $pager;
$this
->updateGlobals();
}
protected function updateGlobals() {
$pager_total_items = [];
$pager_total = [];
$pager_page_array = [];
$pager_limits = [];
foreach ($this->pagers as $pager_id => $pager) {
$pager_total_items[$pager_id] = $pager
->getTotalItems();
$pager_total[$pager_id] = $pager
->getTotalPages();
$pager_page_array[$pager_id] = $pager
->getCurrentPage();
$pager_limits[$pager_id] = $pager
->getLimit();
}
$GLOBALS['pager_total_items'] = new DeprecatedArray($pager_total_items, 'Global variable $pager_total_items is deprecated in drupal:8.8.0 and is removed in drupal:9.0.0. Use \\Drupal\\Core\\Pager\\PagerManagerInterface instead. See https://www.drupal.org/node/2779457');
$GLOBALS['pager_total'] = new DeprecatedArray($pager_total, 'Global variable $pager_total is deprecated in drupal:8.8.0 and is removed in drupal:9.0.0. Use \\Drupal\\Core\\Pager\\PagerManagerInterface instead. See https://www.drupal.org/node/2779457');
$GLOBALS['pager_page_array'] = new DeprecatedArray($pager_page_array, 'Global variable $pager_page_array is deprecated in drupal:8.8.0 and is removed in drupal:9.0.0. Use \\Drupal\\Core\\Pager\\PagerManagerInterface instead. See https://www.drupal.org/node/2779457');
$GLOBALS['pager_limits'] = new DeprecatedArray($pager_limits, 'Global variable $pager_limits is deprecated in drupal:8.8.0 and is removed in drupal:9.0.0. Use \\Drupal\\Core\\Pager\\PagerManagerInterface instead. See https://www.drupal.org/node/2779457');
}
}