Problem/Motivation
In a situation where uswds is the parent theme and there is a custom sub-theme, the uswds-defined process and preprocess hooks will be executed after any process and preprocess hooks which the sub-theme defines traditionally in its .theme file. Only if the sub-theme defines process and preprocess hooks using uswds's process/*.process.inc and preprocess/*.preprocess.inc files will they be ordered as expected with the parent theme's running first and the sub-theme's running second.
The README.md files in examples/*/preprocess and examples/*/process explain how this include process works but describe it as an optional convenience.
Steps to reproduce
- Install Drupal 10
- Install uswds 8.x-2.7
- Make a subtheme following steps in examples/my_subtheme/README.md
- Make an appropriately named mytheme.theme file in the new subtheme with code such as:
function mytheme_preprocess_page(array &$variables) { $variables['test'] = 'mytheme'; } - To the top of the function uswds_preprocess_page in preprocess/layout/page.preprocess.inc add the line:
$variables['test'] = "uswds"; - Add a page.html.twig to the new subtheme, ensuring it outputs
{{test}}. - Viewing a page will show "uswds" as the test variable value even though the active, child theme implements hook_preprocess_page and should have last say.
- Adding breakpoints in each hook reveals they run out of order.
Proposed resolution
Code in base_themes.inc should be adjusted to account for traditionally defined process and preprocess hooks by the active sub-theme. Or, documentation should be updated that any process/preprocess hooks must be defined in the preprocess/*.preprocess.inc and process/*.process.inc files - though this is less ideal as it breaks, instead of supplements, a Drupal convention.
Comments
Comment #2
msielskiComment #3
euk commentedI believe this might be related to another issue (regression) introduced earlier.