class PagerPluginBase
Same name and namespace in other branches
- 11.x core/modules/views/src/Plugin/views/pager/PagerPluginBase.php \Drupal\views\Plugin\views\pager\PagerPluginBase
- 10 core/modules/views/src/Plugin/views/pager/PagerPluginBase.php \Drupal\views\Plugin\views\pager\PagerPluginBase
Base class for views pager plugins.
Hierarchy
- class \Drupal\Component\Plugin\PluginBase extends \Drupal\Component\Plugin\PluginInspectionInterface, \Drupal\Component\Plugin\DerivativeInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses \Drupal\Core\StringTranslation\StringTranslationTrait, \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\Messenger\MessengerTrait implements \Drupal\Component\Plugin\PluginBase
- class \Drupal\views\Plugin\views\PluginBase extends \Drupal\Core\Plugin\ContainerFactoryPluginInterface, \Drupal\views\Plugin\views\ViewsPluginInterface, \Drupal\Component\Plugin\DependentPluginInterface, \Drupal\Core\Security\TrustedCallbackInterface implements \Drupal\Core\Plugin\PluginBase
- class \Drupal\views\Plugin\views\pager\PagerPluginBase implements \Drupal\views\Plugin\views\PluginBase
- class \Drupal\views\Plugin\views\PluginBase extends \Drupal\Core\Plugin\ContainerFactoryPluginInterface, \Drupal\views\Plugin\views\ViewsPluginInterface, \Drupal\Component\Plugin\DependentPluginInterface, \Drupal\Core\Security\TrustedCallbackInterface implements \Drupal\Core\Plugin\PluginBase
- class \Drupal\Core\Plugin\PluginBase uses \Drupal\Core\StringTranslation\StringTranslationTrait, \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\Messenger\MessengerTrait implements \Drupal\Component\Plugin\PluginBase
Expanded class hierarchy of PagerPluginBase
Related topics
3 files declare their use of PagerPluginBase
- DisplayKernelTest.php in core/
modules/ views/ tests/ src/ Kernel/ Plugin/ DisplayKernelTest.php - ResultTest.php in core/
modules/ views/ tests/ src/ Unit/ Plugin/ area/ ResultTest.php - ViewExecutableTest.php in core/
modules/ views/ tests/ src/ Kernel/ ViewExecutableTest.php
File
-
core/
modules/ views/ src/ Plugin/ views/ pager/ PagerPluginBase.php, line 28
Namespace
Drupal\views\Plugin\views\pagerView source
abstract class PagerPluginBase extends PluginBase {
public $current_page = NULL;
public $total_items = 0;
/**
* {@inheritdoc}
*/
protected $usesOptions = TRUE;
/**
* Get how many items per page this pager will display.
*
* All but the leanest pagers should probably return a value here, so
* most pagers will not need to override this method.
*/
public function getItemsPerPage() {
return $this->options['items_per_page'] ?? 0;
}
/**
* Set how many items per page this pager will display.
*
* This is mostly used for things that will override the value.
*/
public function setItemsPerPage($items) {
$this->options['items_per_page'] = $items;
}
/**
* Get the page offset, or how many items to skip.
*
* Even pagers that don't actually page can skip items at the beginning,
* so few pagers will need to override this method.
*/
public function getOffset() {
return $this->options['offset'] ?? 0;
}
/**
* Set the page offset, or how many items to skip.
*/
public function setOffset($offset) {
$this->options['offset'] = $offset;
}
/**
* Get the current page.
*
* If NULL, we do not know what the current page is.
*/
public function getCurrentPage() {
return $this->current_page;
}
/**
* Set the current page.
*
* @param $number
* If provided, the page number will be set to this. If NOT provided,
* the page number will be set from the global page array.
*/
public function setCurrentPage($number = NULL) {
if (!is_numeric($number) || $number < 0) {
$number = 0;
}
$this->current_page = $number;
}
/**
* Get the total number of items.
*
* If NULL, we do not yet know what the total number of items are.
*/
public function getTotalItems() {
return $this->total_items;
}
/**
* Get the pager id, if it exists.
*/
public function getPagerId() {
return $this->options['id'] ?? 0;
}
/**
* Provide the default form for validating options.
*/
public function validateOptionsForm(&$form, FormStateInterface $form_state) {
}
/**
* Provide the default form for submitting options.
*/
public function submitOptionsForm(&$form, FormStateInterface $form_state) {
}
/**
* Returns a string to display as the clickable title for the pager plugin.
*/
public function summaryTitle() {
return $this->t('Unknown');
}
/**
* Determine if this pager actually uses a pager.
*
* Only a couple of very specific pagers will set this to false.
*/
public function usePager() {
return TRUE;
}
/**
* Determine if a pager needs a count query.
*
* If a pager needs a count query, a simple query
*/
public function useCountQuery() {
return TRUE;
}
/**
* Executes the count query.
*
* This will be done just prior to the query itself being executed.
*/
public function executeCountQuery(&$count_query) {
$this->total_items = $count_query->execute()
->fetchField();
if (!empty($this->options['offset'])) {
$this->total_items -= $this->options['offset'];
}
// Prevent from being negative.
$this->total_items = max(0, $this->total_items);
return $this->total_items;
}
/**
* Updates the pager information.
*
* If there are pagers that need global values set, this method can
* be used to set them. It will be called after the query is run.
*/
public function updatePageInfo() {
}
/**
* Modify the query for paging.
*
* This is called during the build phase and can directly modify the query.
*/
public function query() {
}
/**
* Perform any needed actions just prior to the query executing.
*/
public function preExecute(&$query) {
}
/**
* Perform any needed actions just after the query executing.
*/
public function postExecute(&$result) {
}
/**
* Perform any needed actions just before rendering.
*/
public function preRender(&$result) {
}
/**
* Return the renderable array of the pager.
*
* Called during the view render process.
*
* @param $input
* Any extra GET parameters that should be retained, such as exposed
* input.
*/
public function render($input) {
}
/**
* Determine if there are more records available.
*
* This is primarily used to control the display of a more link.
*/
public function hasMoreRecords() {
return $this->getItemsPerPage() && $this->total_items > (intval($this->current_page) + 1) * $this->getItemsPerPage();
}
public function exposedFormAlter(&$form, FormStateInterface $form_state) {
}
public function exposedFormValidate(&$form, FormStateInterface $form_state) {
}
public function exposedFormSubmit(&$form, FormStateInterface $form_state, &$exclude) {
}
public function usesExposed() {
return FALSE;
}
protected function itemsPerPageExposed() {
return FALSE;
}
protected function isOffsetExposed() {
return FALSE;
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.