You are here

function pagerer_test_preprocess_pagerer_base in Pagerer 8

Same name and namespace in other branches
  1. 8.2 tests/modules/pagerer_test/pagerer_test.module \pagerer_test_preprocess_pagerer_base()

Implements hook_preprocess_HOOK().

File

tests/modules/pagerer_test/pagerer_test.module, line 11
Hook implementations for this module.

Code

function pagerer_test_preprocess_pagerer_base(&$variables) {

  // Check if pager is needed; if not, return immediately.
  $pager = \Drupal::service('pagerer.factory')
    ->get($variables['pager']['#element']);
  if ($pager
    ->getTotalPages() <= 1) {
    return;
  }
  foreach ($variables['items']['pages'] as $index => &$pager_item) {
    $pager_item['attributes']['pager-test'] = 'yes';
  }
  unset($pager_item);
  foreach ([
    'first',
    'previous',
    'next',
    'last',
  ] as $special_pager_item) {
    if (isset($variables['items'][$special_pager_item])) {
      $variables['items'][$special_pager_item]['attributes']['pager-test'] = $special_pager_item;
    }
  }
}