Refer to
comment #29 in the issue: "Incorrect order and duplicate theme hook suggestions"
🐛
Incorrect order and duplicate theme hook suggestions
Needs work
I have noticed this same issue, to reiterate the comment above, lets say I have the following theme dependencies:
- foo
-- bar
--- baz
Where baz is the currently enabled theme, which extends bar, which extends foo.
If we were to use hook_theme_suggestions_alter() as an example, Drupal is currently calling these hook implementations in the following order:
- bar_theme_suggestions_alter()
- foo_theme_suggestions_alter()
- baz_theme_suggestions_alter()
This essentially means that bar extends foo, yet foo's hooks override bar.
This isn't the intended order is it?
I beleive this issue stems from \Drupal\Core\Theme\ThemeInitialization::getActiveThemeByName() where it gathers the $base_themes in ascending (reverse) order.
This list of base themes is then used in \Drupal\Core\Theme\ThemeManager::alterForTheme() which takes the list of base themes in reverse order, then tacks on the current theme.
One potential solution for this could be modify \Drupal\Core\Theme\ThemeManager::alterForTheme() to change:
$theme_keys = [];
foreach ($theme->getBaseThemes() as $base) {
$theme_keys[] = $base->getName();
}
to:
$theme_keys = [];
foreach ($theme->getBaseThemes() as $base) {
$theme_keys[] = $base->getName();
}
$theme_keys = array_reverse($theme_keys);