From 3da8c30968476d5b3b7fda87fae724673282b514 Mon Sep 17 00:00:00 2001 From: Lauri Eskola Date: Fri, 2 Jun 2023 10:25:42 +0300 Subject: [PATCH] Issue #3320721 by ranjith_kumar_k_u, martins.bertins, Manibharathi E R, smustgrave, Lendude: The active page number is not showing on the last page(Views Full pager) --- core/includes/theme.inc | 36 +++++++++---------- .../tests/src/Functional/Plugin/PagerTest.php | 16 +++++++++ 2 files changed, 33 insertions(+), 19 deletions(-) diff --git a/core/includes/theme.inc b/core/includes/theme.inc index c8ecdecbee4..a94c697acbd 100644 --- a/core/includes/theme.inc +++ b/core/includes/theme.inc @@ -1814,27 +1814,25 @@ function template_preprocess_pager(&$variables) { } } - if ($i != $pager_max) { - // Add an ellipsis if there are further previous pages. - if ($i > 1) { - $variables['ellipses']['previous'] = TRUE; - } - // Now generate the actual pager piece. - for (; $i <= $pager_last && $i <= $pager_max; $i++) { - $options = [ - 'query' => $pager_manager->getUpdatedParameters($parameters, $element, $i - 1), - ]; - $items['pages'][$i]['href'] = Url::fromRoute($route_name, $route_parameters, $options)->toString(); - $items['pages'][$i]['attributes'] = new Attribute(); - if ($i == $pager_current) { - $variables['current'] = $i; - } - } - // Add an ellipsis if there are further next pages. - if ($i < $pager_max + 1) { - $variables['ellipses']['next'] = TRUE; + // Add an ellipsis if there are further previous pages. + if ($i > 1) { + $variables['ellipses']['previous'] = TRUE; + } + // Now generate the actual pager piece. + for (; $i <= $pager_last && $i <= $pager_max; $i++) { + $options = [ + 'query' => $pager_manager->getUpdatedParameters($parameters, $element, $i - 1), + ]; + $items['pages'][$i]['href'] = Url::fromRoute($route_name, $route_parameters, $options)->toString(); + $items['pages'][$i]['attributes'] = new Attribute(); + if ($i == $pager_current) { + $variables['current'] = $i; } } + // Add an ellipsis if there are further next pages. + if ($i < $pager_max + 1) { + $variables['ellipses']['next'] = TRUE; + } // Create the "next" and "last" links if we are not on the last page. if ($current_page < ($pager_max - 1)) { diff --git a/core/modules/views/tests/src/Functional/Plugin/PagerTest.php b/core/modules/views/tests/src/Functional/Plugin/PagerTest.php index 686e06b6827..f9c70be0813 100644 --- a/core/modules/views/tests/src/Functional/Plugin/PagerTest.php +++ b/core/modules/views/tests/src/Functional/Plugin/PagerTest.php @@ -351,6 +351,22 @@ class PagerTest extends ViewTestBase { // Test pager cache contexts. $this->drupalGet('test_pager_full'); $this->assertCacheContexts(['languages:language_interface', 'theme', 'timezone', 'url.query_args', 'user.node_grants:view']); + + // Set "Number of pager links visible" to 1 and check the active page number + // on the last page. + $view = Views::getView('test_pager_full'); + $view->setDisplay(); + $pager = [ + 'type' => 'full', + 'options' => [ + 'items_per_page' => 5, + 'quantity' => 1, + ], + ]; + $view->display_handler->setOption('pager', $pager); + $view->save(); + $this->drupalGet('test_pager_full', ['query' => ['page' => 2]]); + $this->assertEquals('Current page 3', $this->assertSession()->elementExists('css', '.pager__items li.is-active')->getText()); } /**