You are here

protected function PagererStyleBase::getPageItem in Pagerer 8

Same name and namespace in other branches
  1. 8.2 src/Plugin/pagerer/PagererStyleBase.php \Drupal\pagerer\Plugin\pagerer\PagererStyleBase::getPageItem()

Gets a 'page' item in the pager.

Value returned is dependent on what's being displayed in the pager via the 'display' option, the offset mode selected {absolute|relative}, and whether the page is a progressive one.

Parameters

int $offset: Offset of page to be rendered, from current page.

string $offset_mode: Possible values:

  • 'absolute' returns the page/item/item range at offset.
  • 'relative' returns the offset (pages/items) from current.

bool $progr_page: TRUE indicates a page outside of neighborhood.

string $title_tag: Title tag [page|first|previous|next|last].

bool $set_query: TRUE indicates to build the query parameters for the link.

Return value

array render array of the page item.

5 calls to PagererStyleBase::getPageItem()
Adaptive::buildAdaptivePageList in src/Plugin/pagerer/Adaptive.php
Returns an array of pages using an adaptive logic.
Adaptive::buildPageList in src/Plugin/pagerer/Adaptive.php
Return an array of pages.
Progressive::buildPageList in src/Plugin/pagerer/Progressive.php
Return an array of pages.
Progressive::buildProgressivePageList in src/Plugin/pagerer/Progressive.php
Return an array of pages progressively more distant from current.
Standard::buildNeighborhoodPageList in src/Plugin/pagerer/Standard.php
Return an array of pages in the neighborhood of the current one.

File

src/Plugin/pagerer/PagererStyleBase.php, line 575

Class

PagererStyleBase
Base plugin for Pagerer.

Namespace

Drupal\pagerer\Plugin\pagerer

Code

protected function getPageItem($offset, $offset_mode = 'absolute', $progr_page = FALSE, $title_tag = 'page', $set_query = TRUE) {

  // Get relevant page tag.
  if ($offset == 0) {
    $page_tag_key = 'page_current';
  }
  else {
    if ($progr_page && $offset_mode == 'relative') {
      $page_tag_key = $offset < 0 ? 'page_previous_relative' : 'page_next_relative';
    }
    else {
      $page_tag_key = $offset < 0 ? 'page_previous' : 'page_next';
    }
  }

  // Return if requested not to display current page.
  if ($offset == 0 && $this
    ->getOption('display_mode') == 'none') {
    return [];
  }

  // Link data.
  // - 'text' holds the the formatted page text.
  // - 'title' holds the the formatted HTML title, used by the browser to
  //   display microhelp text.
  // - 'reader_text' holds the the text used by automated readers.
  // - 'href' holds the HTTP URL link to the destination page.
  // - 'is_current' indicates if the page displayed in the pager is the
  //   current page.
  $ret = [
    'text' => $this
      ->getDisplayTag($page_tag_key, $offset),
    'href' => $this->pager
      ->getHref($this->parameters, $this->pager
      ->getCurrentPage() + $offset, NULL, $set_query),
    'title' => $this
      ->getDisplayTag($title_tag . '_title', $offset),
    'reader_text' => $this
      ->getDisplayTag($title_tag . '_reader', $offset),
    'attributes' => new Attribute(),
  ];
  if ($offset == 0) {
    $ret['is_current'] = TRUE;
  }
  return $ret;
}