Problem/Motivation

There is a problem with the Views full pager, the active page number is not showing on the last page when the quantity value is 1.

Steps to reproduce

  • Create a view with full pager
    pager
  • In the pager option the "Number of pager links visible" should be 1
    pager options
  • Go to the view page and go to the last page, the active page is not displaying in the pager
    last page
  • Change the pager option the "Number of pager links visible" to other values then the active page is displaying in the pager
    last page 2

Proposed resolution

This is because the following code on the template_preprocess_pager is not executing on the last page

  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;
    }
  }

The logic behind the check if ($i != $pager_max) { is not documented.
It does not really add up because in the nested for loop $i is allowed to be equal with $pager_max
for (; $i <= $pager_last && $i <= $pager_max; $i++) {

So remove if ($i != $pager_max) { condition from here.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

ranjith_kumar_k_u created an issue. See original summary.

cilefen’s picture

Component: other » views.module
ranjith_kumar_k_u’s picture

A quick fix

ranjith_kumar_k_u’s picture

Status: Active » Needs review
Manibharathi E R’s picture

Patch #3 Applied and Tested successfully on Drupal 9.5.x.

Before Patch:
Before-Patch

After Patch:
After-patch

gaurav-mathur’s picture

FileSize
138.43 KB
165.47 KB

Patch #3 do great work and Tested successfully on Drupal 9.5.x.

Thanks and Regards .

prasanth_kp’s picture

FileSize
127.65 KB
127.77 KB

#3 Patch Applied on 9.5.x-dev and it fixes the issue.

heni_deepak’s picture

Status: Needs review » Reviewed & tested by the community
Lendude’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs tests
  1. +++ b/core/includes/theme.inc
    @@ -1883,6 +1883,18 @@ function template_preprocess_pager(&$variables) {
    +  // To show last active page when "Number of pager links visible"
    +  // is equals to one.
    

    This is not a proper English sentence. Maybe:
    "Make sure the current page is shown if only one page number is shown."
    or something?

  2. +++ b/core/includes/theme.inc
    @@ -1883,6 +1883,18 @@ function template_preprocess_pager(&$variables) {
    +  if ($pager_max == $pager_current && $quantity == 1) {
    

    can we use '===' ?

  3. +++ b/core/includes/theme.inc
    @@ -1883,6 +1883,18 @@ function template_preprocess_pager(&$variables) {
    +    $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();
    +    $variables['current'] = $i;
    

    Is all this really needed? Why is the link removed in the first place? Seems like we should do some more digging into why this breaks at all.

Also, this needs a test. And since the current fix has nothing to do with Views, this seems like a more general problem? But no idea which component this should go into, 'base system' sounds a bit weak too....

martins.bertins’s picture

https://git.drupalcode.org/project/drupal/-/blob/9.5.x/core/includes/the...

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;
  }
}

This part is never executed for last page if pager quantity is set to 1. Unfortunately the logic behind the check if ($i != $pager_max) { is not documented.
It does not really add up because in the nested for loop $i is allowed to be equal with $pager_max
for (; $i <= $pager_last && $i <= $pager_max; $i++) {

Created a new patch that disables the check in question. Needs tests though.

martins.bertins’s picture

Component: views.module » theme system

Changing component

ranjith_kumar_k_u’s picture

Version: 9.5.x-dev » 10.1.x-dev
Status: Needs work » Needs review
FileSize
1.19 KB
1.05 KB
3 KB

Added tests, please review

The last submitted patch, 12: 3320721-12-test-only.patch, failed testing. View results

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: -Needs tests +Needs issue summary update

Issue summary needs to be updated for missing parts.

ranjith_kumar_k_u’s picture

Issue summary: View changes
Status: Needs work » Needs review
smustgrave’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs issue summary update +Needs Review Queue Initiative

Confirmed on 11.x that the last page of a view has the active page link.

  • lauriii committed 3da8c309 on 11.x
    Issue #3320721 by ranjith_kumar_k_u, martins.bertins, Manibharathi E R,...

  • lauriii committed 12690116 on 10.1.x
    Issue #3320721 by ranjith_kumar_k_u, martins.bertins, Manibharathi E R,...
lauriii’s picture

Status: Reviewed & tested by the community » Fixed
FileSize
1.33 KB

Made minor adjustments to the test on commit; adjusted the wrapping of the comment and simplified the selector a bit.

Committed 3da8c30 and pushed to 11.x. Also cherry-picked to 10.1.x. Thanks!

Not going to backport to 10.0.x or 9.5.x because there's a small behavior change.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.