You are here

protected function Standard::buildPagerItems in Pagerer 8

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

Return the pager render array.

Return value

array render array.

File

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

Class

Standard
Pager style alike standard Drupal pager theme.

Namespace

Drupal\pagerer\Plugin\pagerer

Code

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;
}