When a theme preprocess function sets $variables['theme_hook_suggestions'] to change the theme hook, the new theme hook's 'includes' files are not loaded, and its preprocess functions are not run.
Example:
function example_theme() {
return array(
'example_theme_hook' => array( ... , 'file' => 'example.inc' ),
'another_theme_hook' => array( ... ),
);
}
function example_preprocess_example_theme_hook(&$variables) {
// ...
}
function example_preprocess_another_theme_hook(&$variables) {
$variables['theme_hook_suggestions'] = array('example_theme_hook');
// This will not work as expected.
// example_theme_hook will fail, because example.inc will not be loaded.
// Also, example_preprocess_example_theme_hook() will not be called.
}
| Comment | File | Size | Author |
|---|---|---|---|
| #1 | 1224162-include_additional_theme_hook_suggestion_files-1.patch | 550 bytes | bfroehle |
Comments
Comment #1
bfroehle commentedNealB: Can you give the attached patch a try?
Comment #2
NealB-1 commentedThat looks like it would effectively take care of the missing-includes problem. However, when I thought I needed this functionality, I was operating on a flawed understanding of how the theme system works. I was able to find a better solution to the original problem, a solution that didn't need to use 'theme_hook_suggestions'. I don't really know what the use case is for theme_hook_suggestions, so I have no opinion on whether loading secondary includes is actually necessary or desirable. If you wanted to really go the distance, and allow the preprocess function to suggest any arbitrary replacement hook, you would have to re-run essentially the entire theme() function, right? This needs to be resolved by someone with a deeper understanding of the intended functioning of the theme system than I have.
Comment #3
kscheirer#1: 1224162-include_additional_theme_hook_suggestion_files-1.patch queued for re-testing.
Comment #5
sunComment #6
star-szrIn 8.x this was fixed via #2188721: Theme suggestions don't load necessary include files, this can be moved back to 7.x and will need test coverage. The patch in #1 still applies to 7.x.
Comment #7
benjf commentedDuplicate of #2188721: Theme suggestions don't load necessary include files, which now includes this patch. Thanks!