You are here

function template_preprocess_pagerer in Pagerer 8

Same name and namespace in other branches
  1. 8.2 pagerer.module \template_preprocess_pagerer()

Prepares variables for pagerer multi-pane pager templates.

Default template: pagerer.html.twig.

Parameters

array $variables: An associative array containing:

  • pager: A render element containing:

    • #element: (optional) An integer to distinguish between multiple pagers on one page.
    • #parameters: (optional) An associative array of query string parameters to append to the pager links.
    • #config: (optional) An associative array of configuration elements passed on to the styling plugin.

File

./pagerer.module, line 110
Pagerer.

Code

function template_preprocess_pagerer(array &$variables) {

  // Merge with default variables.
  $variables['pager'] = array_merge([
    '#config' => [],
  ], $variables['pager']);

  // Preprocess through the multipane pager plugin.
  $pager = \Drupal::service('pagerer.factory')
    ->get($variables['pager']['#element'])
    ->setRouteName($variables['pager']['#route_name'])
    ->setRouteParameters(isset($variables['pager']['#route_parameters']) ? $variables['pager']['#route_parameters'] : []);
  \Drupal::service('pagerer.style.manager')
    ->createInstance('multipane', $variables['pager']['#config'])
    ->setPager($pager)
    ->preprocess($variables);
}