Problem/Motivation
This ought to be straightforward, but it looks like we've added two required arguments to Theme/Registry::__construct() that should have been ordered before $theme_name, which is optional.
Given this is a constructor and the class is supposed to be internal, I think we could re-order the arguments in 9.5.x, do the deprecation differently, and also have a 10.0.x patch to remove the bc handling.
Steps to reproduce
Proposed resolution
Remaining tasks
User interface changes
API changes
Data model changes
Release notes snippet
| Comment | File | Size | Author |
|---|---|---|---|
| #15 | 3285131-15_9.5.patch | 15.9 KB | andregp |
| #12 | 3285131-12_10.0.patch | 10.89 KB | andregp |
Comments
Comment #2
andregp commented@catch, I couldn't find the $theme_name parameter at the ThemeRegistry::__construct() (link). Am I looking on the wrong place?
Comment #3
catchWhoops, Theme\Registry, not ThemeRegistry..
https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Theme%21R...
Comment #4
andregp commentedSo I tried to create a new deprecation message for the Theme\Registry::__construct() and change the order of the parameters.
I also changed the order at D10 (without adding the deprecation this time).
Comment #5
daffie commented@andregp: Thank you for working on this issue. Both patches look good.
For the D9.5 patch:
Can we change this to:
For the D10 patch:
The $runtime_cache and the $module_list are not optional, therefor they should not have a default value.
Comment #6
andregp commentedAll right, thanks for the feedback @daffie. I'll fix it in a moment.
Comment #7
longwaveEven as a native English speaker the word "antepenultimate" is not familiar to me, I suggest we use "last but one" or something similar instead.
Comment #8
andregp commented@daffie, I changed the code accordingly and tested it by running the related tests (the ones that appear on the patch) without changing them to see if they would throw the deprecation messages correctly. All tests worked (showed the deprecation messages) as expected, except for core/tests/Drupal/KernelTests/Core/Theme/RegistryLegacyTest.php which, even without changing it, worked without triggering the deprecation. I don't know why.
Another problem with
!($runtime_cache instanceof CacheBackendInterface) || !($module_list instanceof ModuleExtensionList)is that some tests actually provide a NULL value for $runtime_cache and/or $module_list which triggers the deprecation even when they are provided on the right order (which reorders the parameters and makes the test fail). See for exampleDrupal\KernelTests\Core\Theme\RegistryTest::testMultipleSubThemesorDrupal\KernelTests\Core\Theme/RegistryLegacyTest::testMultipleSubThemes().The same happens for the D10 patch, removing the NULL option makes the tests fail as they don't provide all the parameters.
Should I modify the tests to always include $runtime_cache and $module_list, or do I just keep these parameters nullable?
Comment #9
andregp commented@longwave sure. I'm sorry for that. I used Google translator to find this term...
I'll wait the response for #8 before fixing it, so I can fix both the wording and the tests on the same patch.
Comment #10
daffie commentedThe tests need to be updated, change it where you set $runtime_cache and $module_list to a real value. That is what we are fixing in this issue.
Comment #11
andregp commented@daffie Okay, thanks for the answer.
I'll do it and send a patch here soon.
Comment #12
andregp commentedThis patch addresses the comments #5 and #10. I didn't address #7 as the message text was changed completely.
Comment #13
longwaveThanks for working on this.
Should be "is required" instead of "is removed" I think?
Also this deprecation needs a test, as there are now three ways of instantiating this object and it's quite confusing to follow.
This can be simplified to
Comment #14
andregp commentedThanks for reviewing @longwave. I'll take a look into this.
Edit.: I didn't know about the #2 syntax, TIL! It's clever and helpful :D
Comment #15
andregp commentedAddressing comment #13.
Comment #16
andregp commented@daffie and @longwave, I was wondering about 2 things:
1 - If we removed the type hints on the last 3 parameters, shouldn't the deprecation be able to handle any order different from the one expected? Something more or less like this:
2 - If we are going to remove the "optionality" of the
$runtime_cacheand$module_listparameters, shouldn't we add a deprecation specific to that (which checks and say they can't be null)?Edit: It could be probably 3 deprecations: wrong order, wrong class, and missing (null) parameter. (or I might be just overshooting the complexity)
Comment #17
daffie commentedThe D9.5 patch is for me RTBC. We also need a patch for D10.
For the D10 patch we need to add the parameter typehints for $runtime_cache and $module_list. Both parameters do not need a default value. In D10 they are required and no longer optional.
Comment #18
andregp commented@daffie The patch I sent on #12 for D10 already removes the default null values and adds back the type hints https://www.drupal.org/files/issues/2022-06-14/3285131-12_10.0.patch
Comment #19
daffie commentedAll code changes look good to me.
Both patches are RTBC for me.
All review points have been addressed.
Comment #21
catchThis looks good to me.
@andregp If we removed the type hints on the last 3 parameters, shouldn't the deprecation be able to handle any order different from the one expected?
Constructor deprecations are best effort, so we only need to handle what was valid previously. Also with this class specifically it's @internal too, so we really don't expect any contrib code to be instantiating or overriding it at all.
Committed/pushed the patches to both branches and pushed to 10.0.x and 9.5.x, thanks!