You are here

pagerer_test.module in Pagerer 8

Same filename and directory in other branches
  1. 8.2 tests/modules/pagerer_test/pagerer_test.module

Hook implementations for this module.

File

tests/modules/pagerer_test/pagerer_test.module
View source
<?php

/**
 * @file
 * Hook implementations for this module.
 */

/**
 * Implements hook_preprocess_HOOK().
 */
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;
    }
  }
}

Functions