You are here

protected function PagerSerializer::pagination in Pager Serializer 8

1 call to PagerSerializer::pagination()
PagerSerializer::render in src/Plugin/views/style/PagerSerializer.php
Render the display in this style.

File

src/Plugin/views/style/PagerSerializer.php, line 90

Class

PagerSerializer
The style plugin for serialized output formats.

Namespace

Drupal\pager_serializer\Plugin\views\style

Code

protected function pagination($config, $rows) {
  $pagination = [];
  $current_page = 0;
  $items_per_page = 0;
  $total_items = 0;
  $total_pages = 1;
  $class = NULL;
  $pager = $this->view->pager;
  if ($pager) {
    $items_per_page = $pager
      ->getItemsPerPage();
    $total_items = $pager
      ->getTotalItems();
    $class = get_class($pager);
  }
  if (method_exists($pager, 'getPagerTotal')) {
    $total_pages = $pager
      ->getPagerTotal();
  }
  if (method_exists($pager, 'getCurrentPage')) {
    $current_page = $pager
      ->getCurrentPage();
  }
  if ($class == static::PAGER_NONE) {
    $items_per_page = $total_items;
  }
  elseif ($class == static::PAGER_SOME) {
    $total_items = count($rows);
  }
  if ($config
    ->get('current_page_enabled')) {
    $current_page_label = $config
      ->get('current_page_label');
    $pagination[$current_page_label] = $current_page;
  }
  if ($config
    ->get('total_items_enabled')) {
    $total_items_label = $config
      ->get('total_items_label');
    $pagination[$total_items_label] = $total_items;
  }
  if ($config
    ->get('total_pages_enabled')) {
    $total_pages_label = $config
      ->get('total_pages_label');
    $pagination[$total_pages_label] = $total_pages;
  }
  if ($config
    ->get('items_per_page_enabled')) {
    $items_per_page_label = $config
      ->get('items_per_page_label');
    $pagination[$items_per_page_label] = $items_per_page;
  }
  return $pagination;
}