class Standard in Pagerer 8
Same name and namespace in other branches
- 8.2 src/Plugin/pagerer/Standard.php \Drupal\pagerer\Plugin\pagerer\Standard
Pager style alike standard Drupal pager theme.
Provides links to the 'neigborhood' of current page, plus first/previous/ next/last page. Extended control on the pager is available through pagerer's specific variables.
Plugin annotation
@PagererStyle(
id = "standard",
title = @Translation("Style like standard Drupal pager"),
short_title = @Translation("Standard"),
help = @Translation("Provides links to the 'neigborhood' of current page, plus first/previous/next/last page; allows extended control on the elements."),
style_type = "base"
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\pagerer\Plugin\pagerer\PagererStyleBase implements ContainerFactoryPluginInterface, PluginFormInterface, PagererStyleInterface
- class \Drupal\pagerer\Plugin\pagerer\Standard
- class \Drupal\pagerer\Plugin\pagerer\PagererStyleBase implements ContainerFactoryPluginInterface, PluginFormInterface, PagererStyleInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of Standard
File
- src/
Plugin/ pagerer/ Standard.php, line 22
Namespace
Drupal\pagerer\Plugin\pagererView source
class Standard extends PagererStyleBase {
/**
* 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 array
* render array of pages items.
*/
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;
}
/**
* Return an array of pages.
*
* @return array
* render array of pages items.
*/
protected function buildPageList() {
return $this
->buildNeighborhoodPageList();
}
/**
* Return the pager render array.
*
* @return array
* render array.
*/
protected function buildPagerItems() {
$pages = $this
->buildPageList();
$items = [];
$previous_page = NULL;
foreach ($pages as $page => $page_data) {
// If not on first page, then introduce a separator or a breaker between
// the pages as configured.
if (isset($previous_page)) {
if ($page == $previous_page + 1) {
// Neighbor page.
if ($this
->getOption('separator_display')) {
$items[] = [
'text' => $this
->getTag('page_separator'),
'is_separator' => TRUE,
'attributes' => new Attribute(),
];
}
}
else {
// Outer page.
if ($this
->getOption('breaker_display')) {
$items[] = [
'text' => $this
->getTag('page_breaker'),
'is_breaker' => TRUE,
'attributes' => new Attribute(),
];
}
elseif ($this
->getOption('separator_display')) {
$items[] = [
'text' => $this
->getTag('page_separator'),
'is_separator' => TRUE,
'attributes' => new Attribute(),
];
}
}
}
elseif ($page != 0 && $this
->getOption('fl_breakers') && $this
->getOption('breaker_display')) {
// If on first link, but current page is not first, introduce a
// breaker before the new link.
$items[] = [
'text' => $this
->getTag('page_breaker'),
'is_breaker' => TRUE,
'attributes' => new Attribute(),
];
}
// Sets previous page.
$previous_page = $page;
$items[] = $page_data;
}
// Introduce a breaker after last page, if needed.
if ($page != $this->pager
->getLastPage() && $this
->getOption('fl_breakers') && $this
->getOption('breaker_display')) {
$items[] = [
'text' => $this
->getTag('page_breaker'),
'is_breaker' => TRUE,
'attributes' => new Attribute(),
];
}
return $items;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
PagererStyleBase:: |
protected | property | The config factory. | |
PagererStyleBase:: |
protected | property | The Pagerer pager object. | |
PagererStyleBase:: |
protected | property | The PagererPreset object being configured. | |
PagererStyleBase:: |
protected | property | The PagererPreset pane being configured. | |
PagererStyleBase:: |
protected | property | Query parameters as requested by the theme call. | |
PagererStyleBase:: |
protected | property | The config type plugins manager. | |
PagererStyleBase:: |
public | function |
Form constructor. Overrides PluginFormInterface:: |
4 |
PagererStyleBase:: |
protected | function | Render a 'no pages to display' text. | 1 |
PagererStyleBase:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
|
PagererStyleBase:: |
protected | function | Returns a translated textual element for pages/items/item ranges. | |
PagererStyleBase:: |
protected | function | Gets a link/button item to first/previous/next/last link. | |
PagererStyleBase:: |
protected | function | Returns a configuration element. | |
PagererStyleBase:: |
protected | function | Gets a 'page' item in the pager. | |
PagererStyleBase:: |
protected | function | Returns a translated textual element from the configuration. | |
PagererStyleBase:: |
protected | function | Prepares input parameters for a JS enabled pager widget. | |
PagererStyleBase:: |
public | function |
Prepares to render the pager. Overrides PagererStyleInterface:: |
|
PagererStyleBase:: |
public | function | Sets the current PagererPreset and pane being configured. | |
PagererStyleBase:: |
public | function |
Sets the Pagerer pager to be rendered. Overrides PagererStyleInterface:: |
|
PagererStyleBase:: |
public | function |
Form submission handler. Overrides PluginFormInterface:: |
|
PagererStyleBase:: |
public | function |
Form validation handler. Overrides PluginFormInterface:: |
|
PagererStyleBase:: |
public | function |
Constructs a \Drupal\pagerer\Plugin\pagerer\PagererStyleBase object. Overrides PluginBase:: |
|
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
Standard:: |
protected | function | Return an array of pages in the neighborhood of the current one. | |
Standard:: |
protected | function | Return an array of pages. | 2 |
Standard:: |
protected | function | Return the pager render array. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |