function template_preprocess_views_mini_pager

Same name in other branches
  1. 9 core/modules/views/views.theme.inc \template_preprocess_views_mini_pager()
  2. 8.9.x core/modules/views/views.theme.inc \template_preprocess_views_mini_pager()
  3. 10 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.
  • pagination_heading_level: An optional heading level for the pager.
  • parameters: Any extra GET parameters that should be retained, such as exposed input.
3 calls to template_preprocess_views_mini_pager()
ViewsPreprocessTest::testEmptyPaginationHeadingLevelSet in core/modules/views/tests/src/Kernel/ViewsPreprocessTest.php
Tests template_preprocess_views_mini_pager() when an empty pagination_heading_level value is passed.
ViewsPreprocessTest::testPaginationHeadingLevelNotSet in core/modules/views/tests/src/Kernel/ViewsPreprocessTest.php
Tests template_preprocess_views_mini_pager() when no pagination_heading_level is passed.
ViewsPreprocessTest::testPaginationHeadingLevelSet in core/modules/views/tests/src/Kernel/ViewsPreprocessTest.php
Tests template_preprocess_views_mini_pager() when a pagination_heading_level value is passed.

File

core/modules/views/views.theme.inc, line 1041

Code

function template_preprocess_views_mini_pager(&$variables) {
    
    /** @var \Drupal\Core\Pager\PagerManagerInterface $pager_manager */
    $pager_manager = \Drupal::service('pager.manager');
    if (empty($variables['pagination_heading_level'])) {
        $variables['pagination_heading_level'] = 'h4';
    }
    $tags =& $variables['tags'];
    $element = $variables['element'];
    $parameters = $variables['parameters'];
    $pager = $pager_manager->getPager($element);
    if (!$pager) {
        return;
    }
    $current = $pager->getCurrentPage();
    $total = $pager->getTotalPages();
    // Current is the page we are currently paged to.
    $variables['items']['current'] = $current + 1;
    if ($total > 1 && $current > 0) {
        $options = [
            'query' => $pager_manager->getUpdatedParameters($parameters, $element, $current - 1),
        ];
        $variables['items']['previous']['href'] = Url::fromRoute('<current>', [], $options)->toString();
        if (isset($tags[1])) {
            $variables['items']['previous']['text'] = $tags[1];
        }
        $variables['items']['previous']['attributes'] = new Attribute();
    }
    if ($current < $total - 1) {
        $options = [
            'query' => $pager_manager->getUpdatedParameters($parameters, $element, $current + 1),
        ];
        $variables['items']['next']['href'] = Url::fromRoute('<current>', [], $options)->toString();
        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';
    $variables['heading_id'] = Html::getUniqueId('pagination-heading');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.