public function PagererStyleBase::preprocess in Pagerer 8
Same name and namespace in other branches
- 8.2 src/Plugin/pagerer/PagererStyleBase.php \Drupal\pagerer\Plugin\pagerer\PagererStyleBase::preprocess()
Prepares to render the pager.
Parameters
array $variables: An associative array containing:
- style: The PagererStyle plugin id to be used to render the pager. Only for base style plugins.
- element: An optional integer to distinguish between multiple pagers on one page.
- parameters: An associative array of query string parameters to append to the pager links.
- config: An associative array of configuration elements for the pager style.
Overrides PagererStyleInterface::preprocess
File
- src/
Plugin/ pagerer/ PagererStyleBase.php, line 403
Class
- PagererStyleBase
- Base plugin for Pagerer.
Namespace
Drupal\pagerer\Plugin\pagererCode
public function preprocess(array &$variables) {
// Save theme requested query parameters.
$this->parameters = $variables['pager']['#parameters'];
// Check if pager is needed; if not, return immediately.
if ($this->pager
->getTotalPages() < $this
->getOption('display_restriction')) {
return;
}
if ($this->pager
->getTotalPages() == 0) {
// Manage empty pageset.
$items['pages'] = $this
->buildEmptyPager();
}
else {
// Compose pager.
$items = [];
// 1 - First + previous links.
if ($this
->getOption('first_link') == 'always' or $this
->getOption('first_link') == 'not_on_first' and $this->pager
->getCurrentPage() != 0) {
$items['first'] = $this
->getNavigationItem('first');
}
if ($this
->getOption('previous_link') == 'always' or $this
->getOption('previous_link') == 'not_on_first' and $this->pager
->getCurrentPage() != 0) {
$items['previous'] = $this
->getNavigationItem('previous');
}
// 2 - Prefix.
if ($this
->getOption('prefix_display')) {
$items['prefix'] = [
'text' => $this
->getDisplayTag('prefix_label'),
'attributes' => new Attribute(),
];
}
// 3 - Pager.
$items['pages'] = $this
->buildPagerItems();
// 4 - Suffix.
if ($this
->getOption('suffix_display')) {
$items['suffix'] = [
'text' => $this
->getDisplayTag('suffix_label'),
'attributes' => new Attribute(),
];
}
// 5 - Next + last links.
if ($this
->getOption('next_link') == 'always' or $this
->getOption('next_link') == 'not_on_last' and $this->pager
->getCurrentPage() != $this->pager
->getLastPage()) {
$items['next'] = $this
->getNavigationItem('next');
}
if ($this
->getOption('last_link') == 'always' or $this
->getOption('last_link') == 'not_on_last' and $this->pager
->getCurrentPage() != $this->pager
->getLastPage()) {
$items['last'] = $this
->getNavigationItem('last');
}
}
// Pager items list.
$variables['items'] = $items;
}