- Issue created by @claudiu.cristea
- ๐ท๐ดRomania claudiu.cristea Arad ๐ท๐ด
Given it has the potential to break sites, I think it's at least major
- Status changed to Needs review
about 1 year ago 1:08pm 20 December 2023 - Issue was unassigned.
- Status changed to Needs work
about 1 year ago 12:28pm 21 December 2023 - ๐ญ๐ทCroatia vulcanr Rijeka
Just tested this locally, and it doesn't work for me unfortunatelly
- Status changed to Needs review
12 months ago 10:51am 4 January 2024 - ๐ท๐ดRomania claudiu.cristea Arad ๐ท๐ด
@vulcanr, it restores the behavior before 10.2.0 for us. Could you, please, add more details about your case?
- ๐ฌ๐งUnited Kingdom alexpott ๐ช๐บ๐
Given that we've regressed here, a small test of the expected functionality would be great to have.
- Status changed to Needs work
12 months ago 11:09am 4 January 2024 - ๐ฌ๐งUnited Kingdom longwave UK
(crosspost with @alexpott)
Given that
ThemeManager::alter()
takes its second context argument ($variables) by reference does imply to me that this is intentional to some extent; if we didn't mean for that to happen we could have not done that when this code was first added. And given that the fix solves a regression and doesn't harm anything else then I think this is fine to add back in.Perhaps as a followup we should add test coverage for this though, if we think it should actually be a supported feature?
- Status changed to Needs review
12 months ago 11:36am 4 January 2024 - ๐ฌ๐งUnited Kingdom longwave UK
Added some test coverage for this (unexpected) feature.
- Status changed to Needs work
12 months ago 11:48am 4 January 2024 - ๐ฌ๐งUnited Kingdom alexpott ๐ช๐บ๐
I think we should update the documentation in theme.api.php to note that $variables is passed in by reference.
- Status changed to Needs review
12 months ago 12:01pm 4 January 2024 - ๐ฌ๐งUnited Kingdom longwave UK
Also updated the docs (and fixed the first arg to hook_theme_suggestions_HOOK_alter() while I was there)
- Status changed to RTBC
12 months ago 12:02pm 4 January 2024 - ๐ฌ๐งUnited Kingdom alexpott ๐ช๐บ๐
@longwave great work on the tests and the docs. Looks great.
- ๐จ๐ฆCanada Charlie ChX Negyesi ๐Canada
that this is intentional to some extent; if we didn't mean for that to happen we could have not done that when this code was first added.
When this code was first added in #678714
theme_hook_suggestions
was a special variable set inhook_preprocess
. At this point variables and suggestions were changeable together simply because they were not separate things yet. The hook was added in #1751194 like thisDrupal::moduleHandler()->alter('theme_suggestions_' . $base_theme_hook, $suggestions, $variables);
. At this point both the hook documentation and the comment at this place only mentions the suggestions as alterable:function hook_theme_suggestions_HOOK_alter(array &$suggestions, array $variables) {
-- $variables , not &$variables. The comment said:// Allow suggestions to be altered via hook_theme_suggestions_HOOK_alter().
instead of "Allow suggestions and variables to be altered". I searched the issue in question for $variable and there was not a single mention of the necessity of them being changeable in suggestions. So everything suggests variables was not supposed to be alterable, it just so happened alter takes everything by reference.As for ThemeManager::alter , that was added in #2228093 as a copy of ModuleHandler::alter. There was no special consideration, it was just copied. The issue didn't discuss any of this either.
This is just to provide a little historical background which is all I do.
- Status changed to Fixed
12 months ago 3:22pm 4 January 2024 - ๐ฌ๐งUnited Kingdom catch
Committed/pushed to 11.x and cherry-picked to 10.2.x, thanks!
Automatically closed - issue fixed for 2 weeks with no activity.