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
In #1912608: Update pagination markup for new CSS standards and improved accessibility, the pager was refactored and new markup was implemented. The twig template contains a hard-coded HMTL ID:
<h4 id="pagination-heading" class="visually-hidden">{{ 'Pagination'|t }}</h4>
This leads to invalid HTML when multiple pagers are present on the same page.
Proposed resolution
- In
template_preprocess_pager()
, build a unique HTML ID dynamically:$variables['pagination_heading_id'] = Html::getUniqueId('pagination-heading');
- In all (* see "remaining tasks" below) instances of page.html.twig, replace
id="pagination-heading"
withid="{{ pagination_heading_id }}"
Remaining tasks
- Decide if the Stable theme needs this update too. I'm not sure what the policy is. On one hand Stable should never change, on the other hand it's a bugfix rather than a change.
- Write code, roll patch, test, etc.
Credits
I nominate my colleague @marloes_bosch for commit credits because she found the issue and figured out how to solve it.
Comment | File | Size | Author |
---|---|---|---|
#15 | interdiff.txt | 1.79 KB | lauriii |
#9 | hard-coded-pagination-heading-id-fix-3011722-9.patch | 3.79 KB | pasan.gamage |
#2 | hard-coded-pagination-heading-id-fix-3011722-2.patch | 3.87 KB | ilya.no |
Comments
Comment #2
ilya.no CreditAttribution: ilya.no as a volunteer and at Skilld for Skilld commentedHi! Attaching initial patch.
Comment #3
Raman Starshykh CreditAttribution: Raman Starshykh at EPAM Systems commentedComment #4
Raman Starshykh CreditAttribution: Raman Starshykh at EPAM Systems commentedPatch serves the purpose as suggested.
I created several views blocks with paginations -
Result html code -
Comment #5
Raman Starshykh CreditAttribution: Raman Starshykh commentedComment #6
alexpottMarkup is not part of the API as per core's BC policy so this change is fine to make. Only going to make it in 8.7.x just in case people have CSS targeting this. It'll give them a chance to target something like
.pager h4
. Also as a bug this should be fixed in stable.Comment #7
lauriiiIs there specific reason why this has been named specifically as
pagination_heading_id
? How about renaming it toheading_id
?We could also open a change record for the change so that people who have overridden the template, know they should apply this change to the overriding template.
Comment #8
marcvangend@ilya.no, thanks for the patch.
Re #7
No, not really. I guess I came up with it because it replaces the id that used to be "pagination-header". But by all means, change it to
heading_id
if that's more consistent with the rest of our code.The change record sounds like a good idea.
Comment #9
pasan.gamage CreditAttribution: pasan.gamage at PreviousNext commentedHi,
Please see attached patch for reverting pagination_heading_id to heading_id
Change request on https://www.drupal.org/node/3018097
Thanks
Comment #10
pasan.gamage CreditAttribution: pasan.gamage at PreviousNext commentedComment #11
Eric115 CreditAttribution: Eric115 at PreviousNext commentedHi Pasan, the change record will need to be about changing the css ID from "pagination-heading" to a unique ID, not about the variable name in this case.
Thanks for your work on this!
Comment #12
pasan.gamage CreditAttribution: pasan.gamage at PreviousNext commentedThank you @Eric115 for mentoring for this issue.
Comment #13
Eric115 CreditAttribution: Eric115 at PreviousNext commentedThanks for updating the change record. The code looks good and is working as per #4.
Marking as RTBC!
Comment #15
lauriiiAdded a full stop after the variable documentation description (interdiff attached). Other than that this looks good. Thank you for creating the change record as well!
Committed 846024a and pushed to 8.7.x. Thanks!
Comment #17
xjmSince this fix required a change to our stable base themes, we'll list it in the release notes since it is a small BC break for themes.