You are here

protected function PagererStyleBase::getDisplayTag in Pagerer 8

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

Returns a translated textual element for pages/items/item ranges.

Depending on the 'display' option, gets a translated text element and formats it to replace placeholders.

Parameters

string $key: The tag key.

int $offset: (Optional) The offset from current page. Defaults to 0.

Return value

string A text tag string.

6 calls to PagererStyleBase::getDisplayTag()
Mini::buildPagerItems in src/Plugin/pagerer/Mini.php
Return the pager render array.
PagererStyleBase::buildEmptyPager in src/Plugin/pagerer/PagererStyleBase.php
Render a 'no pages to display' text.
PagererStyleBase::getNavigationItem in src/Plugin/pagerer/PagererStyleBase.php
Gets a link/button item to first/previous/next/last link.
PagererStyleBase::getPageItem in src/Plugin/pagerer/PagererStyleBase.php
Gets a 'page' item in the pager.
PagererStyleBase::preprocess in src/Plugin/pagerer/PagererStyleBase.php
Prepares to render the pager.

... See full list

File

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

Class

PagererStyleBase
Base plugin for Pagerer.

Namespace

Drupal\pagerer\Plugin\pagerer

Code

protected function getDisplayTag($key, $offset = 0) {

  // Get the translated tag, with placeholders.
  $tag = $this
    ->getTag($this
    ->getOption('display') . '.' . $key);

  // Items.
  $l_item = ($this->pager
    ->getCurrentPage() + $offset) * $this->pager
    ->getLimit() + 1;
  $h_item = min(($this->pager
    ->getCurrentPage() + $offset + 1) * $this->pager
    ->getLimit(), $this->pager
    ->getTotalItems());
  $item_offset = abs($offset * $this->pager
    ->getLimit());

  // Pages.
  $number = $this->pager
    ->getCurrentPage() + $offset + 1;
  $t_offset = abs($offset);

  // Return the formatted tag.
  return new FormattableMarkup($tag, [
    '@number' => $number,
    '@offset' => $t_offset,
    '@total' => $this->pager
      ->getTotalPages(),
    '@item_low' => $l_item,
    '@item_high' => $h_item,
    '@item' => $l_item,
    '@item_offset' => $item_offset,
    '@total_items' => $this->pager
      ->getTotalItems(),
  ]);
}