Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
#2349991: Provide a trait for categorizing plugin managers and use it for conditions and actions added this code with no test coverage. The unsetting of 'broken' in getGroupedDefinitions is redundant, since it always calls getSortedDefinitions first.
While unset() doesn't trigger notices for missing keys, it does for subkeys of missing keys:
unset($definitions[$this->t('Block')]['broken']);
will always fail.
Proposed resolution
Don't do the unnecessary unset, add tests that would have caught this.
Remaining tasks
N/A
User interface changes
N/A
API changes
N/A
Data model changes
N/A
Comment | File | Size | Author |
---|---|---|---|
#10 | 2884769-10.pass_.patch | 4.51 KB | larowlan |
#10 | 2884769-10.fail_.patch | 2.98 KB | larowlan |
#9 | 2884769-9.patch | 4.51 KB | larowlan |
#9 | interdiff.2884769-9.txt | 819 bytes | larowlan |
#7 | 2884769-block-broken-7.patch | 4.43 KB | tim.plunkett |
Comments
Comment #2
tim.plunkettComment #3
tim.plunkettThe entire method override is unnecessary, actually.
Comment #4
tim.plunkett@tedbow points out that asserting for those specific 4 blocks is odd.
Those are the 4 that are provided by subsystems, and are available when no modules are enabled. But this test would be brittle, and fail if other subsystems provide blocks in the future.
Therefore I rewrote the test as a unit test.
Comment #5
tedbowCould put a 1 block in "expected_category_1" and 2 in expected "expected_category_2" to prove it will be group into multiple categories correctly?
Comment #7
tim.plunkettGood idea. I used real strings, since that is the intention of the category.
Comment #8
tedbow@tim.plunkett looks good! RTBC 🎉!
Comment #9
larowlanSo reviewed this and found that the test fails in HEAD, but not because it catches the bug (we don't have a test only patch for the new test).
Because the existing code tries to unset on the translated string
Attached patch sets a mock string translation service on the manager in the test.
Which then yields
Which is the expected fail.
I think this is ready too - thanks.
Comment #10
larowlanjust for completeness here's fail/pass patches
Comment #12
tedbowSo since @larowlan
Setting back to RTBC because of expected pass/fail in #10
Comment #13
tim.plunkettExcept that string translation is no longer needed after this patch.
While the interdiff in #9 is necessary for the FAIL patch, it's not for the PASS patch.
Doesn't really matter to me...
The confusion stems from the same issue that introduced this bug, linked in the IS:
CategorizingPluginManagerTrait has NO need to use StringTranslationTrait.
But removing that might be a problem, and is out of scope.
Comment #14
Gábor HojtsyComment #17
Gábor HojtsyGood find @larowlan. Looks like everyone agrees this is the better fix, so went ahead and committed it. Verified that the method from the trait looks good and already filters out the broken plugin.