Problem/Motivation
In Twig debug comments, Theme suggestions should be listed with the most-specific ones first and more-generic ones later. When a View has a "more link" added to it, the suggestions for its container are in the reverse order from what they should be.
<!-- FILE NAME SUGGESTIONS:
* container--more-link.html.twig
* container--more-link--frontpage.html.twig
* container--more-link--page.html.twig
* container--more-link--frontpage--page.html.twig
* container--more-link--default.html.twig
* container--more-link--page-1.html.twig
* container--more-link--frontpage--page-1.html.twig
x container.html.twig
-->
The container--more-link--frontpage--page-1.html.twig is more specific than container--more-link.html.twig, so it should come before it in the list.
This is caused because of a bug in views_theme_suggestions_container_alter() which uses ViewExecutable::buildThemeFunctions() incorrectly. ViewExecutable::buildThemeFunctions() returns theme suggestions in the same order as needed for a #theme entry in a render array. But all the theme suggestions hooks require suggestions in the opposite order (to make adding more-specific suggestions as easy as appending to an array.)
Steps to reproduce
Edit the frontpage view (/admin/structure/views/view/frontpage) and turn on the "more link" option. Then visit the /node page and look at the new "more" link at the bottom of the node list.
Proposed resolution
Perform an array_reverse() on the results of ViewExecutable::buildThemeFunctions() before using it in views_theme_suggestions_container_alter().
User interface changes
None.
API changes
None.
Release notes snippet
The Views "more link" now lists theme suggestions in the proper order. For example, a container--more-link--frontpage.html.twig template will now override a container--more-link.html.twig template.
| Comment | File | Size | Author |
|---|
Issue fork drupal-3188122
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
johnalbinComment #4
lendudeDid a little digging a to why we are doing this at all, but seems to stem from #2036195: Remove views-more.html.twig and replace with #type link render arrays and trying to maintain some sort of feature parity when the views specific more template was removed. I think.....
Looks good, nice test coverage. One thing, the new test isn't using the browser, so can we do that in a kernel test please? Maybe add it to \Drupal\Tests\views\Kernel\Plugin\DisplayPageTest since that already does some read more testing?
Comment #5
johnalbinThanks for the review! And I'll start working on refactoring the tests to use kernal tests instead.
Comment #6
johnalbinOK. I've moved the tests to ViewsTemplateTest which extends ViewsKernelTestBase.
Comment #10
dwwCame upon this bug while working on a client site today. Excited to see this looks basically ready and done. Tagging to be smashed. Hope to have time to review this week. 🤞
Comment #11
steveoriolThis MR can not be not apply if the MR from #2118743: Twig debug output does not display all suggestions when an array of theme hooks is passed to #theme is used.
Comment #12
abhijith s commentedApplied MR 152 on 9.5.x and fixes the issue.The template suggestion hierarchy is appearing correctly after applying this patch.
After patch:

RTBC +1
Comment #13
smustgrave commentedTested the PR and confirmed it works as described
Comment #14
dwwAgreed, this looks ready:
assertStringContainsString()works, and that seems to make the most sense for this test.RTBC++ 😉
Thanks!
-Derek
Comment #15
quietone commentedThe MR is testing on 9.3. That needs to be updated to 9.5. Or maybe switch to a patch so we can test on multiple versions easily.
Comment #16
johnalbinI'll try to get this rebased on 10.1.x during Drupalcon Prague this week.
Comment #17
johnalbinI merged 10.1.x into this branch and I didn't have to fix any merge conflicts. Hopefully, the tests will pass and this will re ready to RTBC again.
Comment #18
smustgrave commentedThis is was on my list of tickets to review. I just rebased the branch.
Also tested out manually and confirmed it was working.
Comment #21
larowlanRebased the 10.1.x branch and made a 9.5.x version
If they both pass I'll commit this. Ideally the 9.5.x version was done before it was RTBC (it was asked for in #15) but 🤷
Comment #22
quietone commentedSetting to NW because of failing tests.
Comment #27
larowlanClosed related issue as a Duplicate of this one
Adding credit from the other one
Comment #28
lendudeThe 9.5 version only seems to contain the test changes? So not too shocking that it fails ;)
Comment #29
larowlanSounds like I messed that up, will look today
Comment #30
larowlanAdded all three commits this time, if someone else is willing to RTBC this I still think I'm eligible to commit it as all I'm doing is git commands
Comment #31
smustgrave commentedChanges look good.
Also the MR does apply for 10.1.
Comment #32
larowlanRemoving credit for my failed branch work
Comment #37
larowlanCommitted to 10.1.x and backported to 10.0.x and 9.5.x
Thanks