protected function Standard::buildNeighborhoodPageList in Pagerer 8
Same name and namespace in other branches
- 8.2 src/Plugin/pagerer/Standard.php \Drupal\pagerer\Plugin\pagerer\Standard::buildNeighborhoodPageList()
Return an array of pages in the neighborhood of the current one.
This is in fact generating the same list of pages as standard Drupal pager. The neighborhood is centered on the current page, with ($this->getOption('quantity') / 2) pages falling aside left and right of the current, provided there are enough pages.
Return value
array render array of pages items.
3 calls to Standard::buildNeighborhoodPageList()
- Adaptive::buildPageList in src/
Plugin/ pagerer/ Adaptive.php - Return an array of pages.
- Progressive::buildPageList in src/
Plugin/ pagerer/ Progressive.php - Return an array of pages.
- Standard::buildPageList in src/
Plugin/ pagerer/ Standard.php - Return an array of pages.
File
- src/
Plugin/ pagerer/ Standard.php, line 35
Class
- Standard
- Pager style alike standard Drupal pager theme.
Namespace
Drupal\pagerer\Plugin\pagererCode
protected function buildNeighborhoodPageList(array $pages = []) {
$quantity = $this
->getOption('quantity');
// Middle is used to "center" pages around the current page.
$pager_middle = ceil($quantity / 2);
// Current is the page we are currently paged to.
$pager_current = $this->pager
->getCurrentPage() + 1;
// First is the first page listed by this pager piece (re quantity).
$pager_first = $pager_current - $pager_middle + 1;
// Last is the last page listed by this pager piece (re quantity).
$pager_last = $pager_current + $quantity - $pager_middle;
// Prepare for generation loop.
$i = $pager_first;
// Adjust "center" if at end of query.
if ($pager_last > $this->pager
->getTotalPages()) {
$i = $i + ($this->pager
->getTotalPages() - $pager_last);
$pager_last = $this->pager
->getTotalPages();
}
// Adjust "center" if at start of query.
if ($i <= 0) {
$pager_last = $pager_last + (1 - $i);
$i = 1;
}
for (; $i <= $pager_last && $i <= $this->pager
->getTotalPages(); $i++) {
$offset = $i - $pager_current;
if (!isset($pages[$i - 1])) {
$pages[$i - 1] = $this
->getPageItem($offset, 'absolute', FALSE, $offset ? 'page' : 'page_current');
}
}
return $pages;
}