Closed (outdated)
Project:
Drupal core
Version:
main
Component:
theme system
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
25 Nov 2020 at 14:15 UTC
Updated:
25 Jul 2026 at 11:11 UTC
Jump to comment: Most recent
According to theme.api.php, this is the signature of hook_theme_suggestions_alter() and hook_theme_suggestions_HOOK_alter():
function hook_theme_suggestions_alter(array &$suggestions, array $variables, $hook)
Note that $variables is NOT passed by reference.
However, in ThemeManager::render(), we see something different:
// Invoke hook_theme_suggestions_alter() and
// hook_theme_suggestions_HOOK_alter().
$hooks = [
'theme_suggestions',
'theme_suggestions_' . $base_theme_hook,
];
$this->moduleHandler->alter($hooks, $suggestions, $variables, $base_theme_hook);
$this->alter($hooks, $suggestions, $variables, $base_theme_hook);
Those alter() calls are passing $variables by reference.
N/A
Make sure the documented function signatures are accurate, and explicitly state that $variables is passed by reference.
Fix it.
None.
Nope, but better documentation!
None.
TBD, likely none.
Comments
Comment #8
quietone commentedThis was fixed in #3409982: [D10.2 regression] Theme suggestions cannot alter variables anymore
I am closing this as outdated.