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

  1. Install Drupal 10
  2. Install uswds 8.x-2.7
  3. Make a subtheme following steps in examples/my_subtheme/README.md
  4. Make an appropriately named mytheme.theme file in the new subtheme with code such as:
    function mytheme_preprocess_page(array &$variables) {
      $variables['test'] = 'mytheme';
    }
    
  5. To the top of the function uswds_preprocess_page in preprocess/layout/page.preprocess.inc add the line:
    $variables['test'] = "uswds";
  6. Add a page.html.twig to the new subtheme, ensuring it outputs {{test}}.
  7. 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.
  8. 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.

Remaining tasks

User interface changes

API changes

Data model changes

Comments

msielski created an issue. See original summary.

msielski’s picture

Issue summary: View changes
euk’s picture

I believe this might be related to another issue (regression) introduced earlier.