You are here

function template_preprocess_views_mini_pager in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/views/views.theme.inc \template_preprocess_views_mini_pager()

Prepares variables for views mini-pager templates.

Default template: views-mini-pager.html.twig.

Parameters

array $variables: An associative array containing:

  • tags: Provides link text for the next/previous links.
  • element: The pager's id.
  • parameters: Any extra GET parameters that should be retained, such as exposed input.

File

core/modules/views/views.theme.inc, line 972
Preprocessors and helper functions to make theming easier.

Code

function template_preprocess_views_mini_pager(&$variables) {
  global $pager_page_array, $pager_total;
  $tags =& $variables['tags'];
  $element = $variables['element'];
  $parameters = $variables['parameters'];

  // Current is the page we are currently paged to.
  $variables['items']['current'] = $pager_page_array[$element] + 1;
  if ($pager_total[$element] > 1 && $pager_page_array[$element] > 0) {
    $options = array(
      'query' => pager_query_add_page($parameters, $element, $pager_page_array[$element] - 1),
    );
    $variables['items']['previous']['href'] = \Drupal::url('<current>', [], $options);
    if (isset($tags[1])) {
      $variables['items']['previous']['text'] = $tags[1];
    }
    $variables['items']['previous']['attributes'] = new Attribute();
  }
  if ($pager_page_array[$element] < $pager_total[$element] - 1) {
    $options = array(
      'query' => pager_query_add_page($parameters, $element, $pager_page_array[$element] + 1),
    );
    $variables['items']['next']['href'] = \Drupal::url('<current>', [], $options);
    if (isset($tags[3])) {
      $variables['items']['next']['text'] = $tags[3];
    }
    $variables['items']['next']['attributes'] = new Attribute();
  }

  // This is based on the entire current query string. We need to ensure
  // cacheability is affected accordingly.
  $variables['#cache']['contexts'][] = 'url.query_args';
}