You are here

class Standard in Pagerer 8

Same name and namespace in other branches
  1. 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

Expanded class hierarchy of Standard

File

src/Plugin/pagerer/Standard.php, line 22

Namespace

Drupal\pagerer\Plugin\pagerer
View 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

Namesort descending Modifiers Type Description Overrides
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function 1
DependencySerializationTrait::__wakeup public function 2
MessengerTrait::$messenger protected property The messenger. 29
MessengerTrait::messenger public function Gets the messenger. 29
MessengerTrait::setMessenger public function Sets the messenger.
PagererStyleBase::$configFactory protected property The config factory.
PagererStyleBase::$pager protected property The Pagerer pager object.
PagererStyleBase::$pagererPreset protected property The PagererPreset object being configured.
PagererStyleBase::$pagererPresetPane protected property The PagererPreset pane being configured.
PagererStyleBase::$parameters protected property Query parameters as requested by the theme call.
PagererStyleBase::$typedConfigManager protected property The config type plugins manager.
PagererStyleBase::buildConfigurationForm public function Form constructor. Overrides PluginFormInterface::buildConfigurationForm 4
PagererStyleBase::buildEmptyPager protected function Render a 'no pages to display' text. 1
PagererStyleBase::create public static function Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface::create
PagererStyleBase::getDisplayTag protected function Returns a translated textual element for pages/items/item ranges.
PagererStyleBase::getNavigationItem protected function Gets a link/button item to first/previous/next/last link.
PagererStyleBase::getOption protected function Returns a configuration element.
PagererStyleBase::getPageItem protected function Gets a 'page' item in the pager.
PagererStyleBase::getTag protected function Returns a translated textual element from the configuration.
PagererStyleBase::prepareJsState protected function Prepares input parameters for a JS enabled pager widget.
PagererStyleBase::preprocess public function Prepares to render the pager. Overrides PagererStyleInterface::preprocess
PagererStyleBase::setConfigurationContext public function Sets the current PagererPreset and pane being configured.
PagererStyleBase::setPager public function Sets the Pagerer pager to be rendered. Overrides PagererStyleInterface::setPager
PagererStyleBase::submitConfigurationForm public function Form submission handler. Overrides PluginFormInterface::submitConfigurationForm
PagererStyleBase::validateConfigurationForm public function Form validation handler. Overrides PluginFormInterface::validateConfigurationForm
PagererStyleBase::__construct public function Constructs a \Drupal\pagerer\Plugin\pagerer\PagererStyleBase object. Overrides PluginBase::__construct
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::$pluginId protected property The plugin_id.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition 3
PluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::isConfigurable public function Determines if the plugin is configurable.
Standard::buildNeighborhoodPageList protected function Return an array of pages in the neighborhood of the current one.
Standard::buildPageList protected function Return an array of pages. 2
Standard::buildPagerItems protected function Return the pager render array.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.