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.
hook_theme provides a way to place theme functions in a different location using the 'file' key. But when that theme function is used in context of theme_suggestions_alter the path defined in 'file' doesn't get included. Attached patch fixes it.
Comment | File | Size | Author |
---|---|---|---|
#16 | 2188721-16.patch | 4.46 KB | benjf |
#14 | 2188721-14-fail.patch | 3.92 KB | star-szr |
#7 | 2188721-7.patch | 7.2 KB | star-szr |
#7 | 2188721-7-testonly.patch | 6.07 KB | star-szr |
Comments
Comment #1
aspilicious CreditAttribution: aspilicious commentedComment #2
star-szrThanks! Tagging for test coverage.
Comment #3
star-szrComment #4
star-szrI'm working on this.
Comment #5
star-szr@aspilicious - I actually can't seem to reproduce this in a test - can you point me to or post a concrete example of this happening? Is this a module or a theme or a combination of the two?
Basically in my test I have two hook_theme() implementations pointing to theme functions, both are in modules that are installed. Theme function A is in the .module, theme function B is in a .inc file specified in 'file' in the hook_theme(). I call theme hook A then use hook_theme_suggestions_HOOK_alter() to redirect to B, but the include file gets loaded just fine.
I'm thinking we should actually just move the existing "include" code down below the suggestion hooks since I can't see where it's useful to have that until just before theme functions and preprocess functions are called anyway.
Comment #6
star-szr@aspilicious got in touch with me on IRC and provided some sample code, so I will continue to dig in here.
Comment #7
star-szrTurns out I just needed to drupalGet() twice because the theme registry is being rebuilt during the first request :)
Failing test + fix attached.
Comment #9
aspilicious CreditAttribution: aspilicious commentedWorks for me :)
Comment #10
catchCode looks the same in 7.x as well, should this be tagged for backport?
Comment #11
star-szrPossibly, I can try to backport the test after commit and see what happens, at the very least we can add more test coverage to 7.x.
Comment #12
catchCommitted/pushed to 8.x, thanks!
Comment #13
star-szrHaving lack of internet problems but I am working on a test for 7.x and it fails, so as far as I can tell this wasn't a regression. Will have at least the failing test up within a few days.
Comment #14
star-szrHere's the failing test for 7.x as promised. Unassigning in case I don't have time to come back to this soon.
Comment #16
benjf CreditAttribution: benjf commentedpatch from #1224162-1: When a preprocess function sets theme_hook_suggestions, the suggested theme hook's 'includes' are not loaded combined with the test from #14
Comment #17
star-szrThanks @benjf! Sending to the bot.
Comment #18
star-szrCool, it's green! Since there's already this code further up in theme():
The second include_once would only be used for theme suggestions in D7 so a couple things:
if $hook != $suggestion
(well, something along those lines anyway).