class Progressive in Pagerer 8
Same name and namespace in other branches
- 8.2 src/Plugin/pagerer/Progressive.php \Drupal\pagerer\Plugin\pagerer\Progressive
Pager style with links to pages progressively more distant from current.
Besides links to the 'neigborhood' of current page, creates a list of links which are progressively more distant from current page, displaying either a page number or an offset from current page.
This is controlled via the 'progr_links' theme variable, which can take a value either 'absolute' or 'relative'.
Examples:
page 9 out of 212, progr_links 'absolute', display 'pages': ------------------------------------------------------------------- 1 . 4 . 7 8 [9] 10 11 . 14 . 19 . 59 . 109 . 212 -------------------------------------------------------------------
page 9 out of 212, progr_links 'relative', display 'pages': ------------------------------------------------------------------- 1 . -5 . 7 8 [9] 10 11 . +5 . +10 . +50 . +100 . 212 -------------------------------------------------------------------
The 'factors' theme variable controls the quantity of progressive links generated. Each value in the comma delimited string will be used as a scale factor for a progressive series of pow(10, n).
Examples: 'factors' => '10' will generate links for page offsets
..., -1000, -100, -10, 10, 100, 1000, ....
'factors' => '5,10' will generate links for page offsets
..., -1000, -500, -100, -50, -10, -5, 5, 10, 50, 100, 500, 1000, ....
etc.
Plugin annotation
@PagererStyle(
id = "progressive",
title = @Translation("Pager style with links to pages progressively more distant"),
short_title = @Translation("Progressive"),
help = @Translation("Besides links to the 'neigborhood' of current page, creates a list of links which are progressively more distant from current page, displaying either a page number or an offset from current page."),
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\Progressive
- 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 Progressive
File
- src/
Plugin/ pagerer/ Progressive.php, line 52
Namespace
Drupal\pagerer\Plugin\pagererView source
class Progressive extends Standard {
/**
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$config = parent::buildConfigurationForm($form, $form_state);
$config['display_container']['factors'] = [
'#type' => 'textfield',
'#title' => $this
->t("Scale factors"),
'#default_value' => $this->configuration['factors'],
'#description' => $this
->t("Comma delimited string of factors to use to determine progressive links."),
'#required' => TRUE,
];
return $config;
}
/**
* {@inheritdoc}
*/
protected function buildPageList() {
$current = $this->pager
->getCurrentPage();
$last = $this->pager
->getLastPage();
// First.
$pages[0] = $this
->getPageItem(-$current, 'absolute', FALSE, $current == 0 ? 'page_current' : 'page');
// Last.
$pages[$last] = $this
->getPageItem($last - $current, 'absolute', FALSE, $current == $last ? 'page_current' : 'page');
// Neighborhood.
$pages = $this
->buildNeighborhoodPageList($pages);
// Progressive.
if ($this
->getOption('factors')) {
$factors = explode(',', $this
->getOption('factors'));
foreach ($factors as $scale_factor) {
$pages = $this
->buildProgressivePageList($pages, $scale_factor, 10);
}
}
ksort($pages);
return $pages;
}
/**
* Return an array of pages progressively more distant from current.
*
* @param array $pages
* Array of pages already enlisted, to prevent override.
* @param int $scale_factor
* Scale factor to be used in the progressive series.
* @param int $ratio
* Ratio to be used in the progressive series.
* @param int $limit
* (Optional) limit the quantity of pages enlisted.
*
* @return array
* render array of pages items.
*/
protected function buildProgressivePageList(array $pages, $scale_factor, $ratio, $limit = NULL) {
$current = $this->pager
->getCurrentPage();
$total = $this->pager
->getTotalPages();
$last = $this->pager
->getLastPage();
// Avoid endless loop in converging series.
if ($ratio < 1) {
$ratio = 1;
}
$offset = 0;
for ($i = 0; TRUE; $i++) {
// Breaks if limit reached.
if ($limit and $i > $limit - 1) {
break;
}
// Offset for this cycle.
$offset = intval($scale_factor * pow($ratio, $i));
// Breaks if offset > than total pages.
if ($offset > $total) {
break;
}
// Negative offset.
$target = $current - $offset;
if ($target > 0 && !isset($pages[$target])) {
$pages[$target] = $this
->getPageItem(-$offset, $this
->getOption('progr_links'), TRUE);
}
// Positive offset.
$target = $current + $offset;
if ($target < $last && !isset($pages[$target])) {
$pages[$target] = $this
->getPageItem($offset, $this
->getOption('progr_links'), TRUE);
}
}
return $pages;
}
}
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:: |
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. | |
Progressive:: |
public | function |
Form constructor. Overrides PagererStyleBase:: |
|
Progressive:: |
protected | function |
Return an array of pages. Overrides Standard:: |
|
Progressive:: |
protected | function | Return an array of pages progressively more distant from current. | |
Standard:: |
protected | function | Return an array of pages in the neighborhood of the current one. | |
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. |