You are here

function pager_test_preprocess_pager in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/system/tests/modules/pager_test/pager_test.module \pager_test_preprocess_pager()
  2. 10 core/modules/system/tests/modules/pager_test/pager_test.module \pager_test_preprocess_pager()

Implements hook_preprocess_HOOK().

File

core/modules/system/tests/modules/pager_test/pager_test.module, line 11
Hook implementations for this module.

Code

function pager_test_preprocess_pager(&$variables) {

  // Nothing to do if there is only one page.
  $element = $variables['pager']['#element'];

  /** @var \Drupal\Core\Pager\PagerManagerInterface $pager_manager */
  $pager_manager = \Drupal::service('pager.manager');
  $pager = $pager_manager
    ->getPager($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;
    }
  }
}