Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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
- In the pager option the "Number of pager links visible" should be 1
- Go to the view page and go to the last page, the active page is not displaying in the pager
- Change the pager option the "Number of pager links visible" to other values then the active page is displaying in the pager
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
Comment | File | Size | Author |
---|---|---|---|
#19 | interdiff.txt | 1.33 KB | lauriii |
#12 | 3320721-12.patch | 3 KB | ranjith_kumar_k_u |
| |||
#12 | interdiff_10-12.txt | 1.05 KB | ranjith_kumar_k_u |
#12 | 3320721-12-test-only.patch | 1.19 KB | ranjith_kumar_k_u |
#10 | 3320721-10.patch | 1.82 KB | martins.bertins |
Comments
Comment #2
cilefen CreditAttribution: cilefen as a volunteer commentedComment #3
ranjith_kumar_k_u CreditAttribution: ranjith_kumar_k_u as a volunteer and at Srijan | A Material+ Company for Drupal India Association commentedA quick fix
Comment #4
ranjith_kumar_k_u CreditAttribution: ranjith_kumar_k_u as a volunteer and at Srijan | A Material+ Company for Drupal India Association commentedComment #5
Manibharathi E R CreditAttribution: Manibharathi E R at Srijan | A Material+ Company for Srijan | A Material+ Company commentedPatch #3 Applied and Tested successfully on Drupal 9.5.x.
Before Patch:
After Patch:
Comment #6
gaurav-mathur CreditAttribution: gaurav-mathur at Dotsquares Ltd. commentedPatch #3 do great work and Tested successfully on Drupal 9.5.x.
Thanks and Regards .
Comment #7
prasanth_kp CreditAttribution: prasanth_kp as a volunteer and at Zyxware Technologies commented#3 Patch Applied on 9.5.x-dev and it fixes the issue.
Comment #8
heni_deepak CreditAttribution: heni_deepak at Dotsquares Ltd. commentedComment #9
LendudeThis is not a proper English sentence. Maybe:
"Make sure the current page is shown if only one page number is shown."
or something?
can we use '===' ?
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....
Comment #10
martins.bertins CreditAttribution: martins.bertins at Wunder commentedhttps://git.drupalcode.org/project/drupal/-/blob/9.5.x/core/includes/the...
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.
Comment #11
martins.bertins CreditAttribution: martins.bertins at Wunder commentedChanging component
Comment #12
ranjith_kumar_k_u CreditAttribution: ranjith_kumar_k_u as a volunteer and at Srijan | A Material+ Company for Drupal India Association commentedAdded tests, please review
Comment #14
smustgrave CreditAttribution: smustgrave at Mobomo commentedIssue summary needs to be updated for missing parts.
Comment #15
ranjith_kumar_k_u CreditAttribution: ranjith_kumar_k_u as a volunteer and at Srijan | A Material+ Company for Drupal India Association commentedComment #16
smustgrave CreditAttribution: smustgrave at Mobomo commentedConfirmed on 11.x that the last page of a view has the active page link.
Comment #19
lauriiiMade 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.