Problem/Motivation
The #2671964: ContextHandler cannot validate constraints introduced a new method called isSatisfiedBy(ContextInterface $context) which checks if given context satisfies context deifinition.
There is a following condition in this method:
elseif ($definition instanceof static) {
$values = $definition->getSampleValues();
}
This condition fails if the ContextDefinition object is an instance of inherited class in which case it becomes:
elseif ($definition instanceof SomeClassExtendingContextDefinition) {
$values = $definition->getSampleValues();
}
In a real life, the Rules module replaces context definition plugins with it's own, extending core.
Proposed resolution
The condition above should be checking 'instanceof self' instead of 'instanceof static'.
Remaining tasks
Review.
User interface changes
None.
API changes
None.
Data model changes
None.
Comment | File | Size | Author |
---|---|---|---|
#3 | core-is_satisfied_extended_context_test_and_fix-2958785-3.patch | 2.23 KB | abramm |
#2 | core-is_satisfied_extended_context_test-2958785-2.patch | 1.63 KB | abramm |
Comments
Comment #2
abrammThe test in this patch is expected to fail.
Comment #3
abrammPatch with test + fix.
Comment #4
abrammComment #5
abrammComment #6
tim.plunkettWow, nice find. I'm so used to thinking of it from the other direction when it comes to self vs static, this probably didn't even occur to me.
Test coverage is good, thanks for that.
Comment #7
tim.plunkettComment #8
hd CreditAttribution: hd commentedIn my core 8.5.1 system in core/lib/Drupal/Core/Plugin/Context/ContextDefinition.php in function isSatisfiedBy() I changed
// elseif ($definition instanceof static) {
elseif ($definition instanceof self) {
and the two other changes as per patch https://www.drupal.org/files/issues/2018-04-05/core-is_satisfied_extende... and can confirm this fixes the problem. Now block visibility setting tab for Content types is showing when the Rules module is installed, and it also works as intended. Originally I reported the issue at https://www.drupal.org/project/rules/issues/2956908. Thanks everyone for getting to the bottom of this.
Comment #9
Madis CreditAttribution: Madis as a volunteer commentedClosed issues #2955370 and #2956908 as duplicates and as mentioned in the oldest one I can also confirm that this patch fixes block visibility settings with the Rules module installed (tested with latest core and Rules dev versions).
Comment #10
alexpottCommitted and pushed e817928144 to 8.6.x and d77ed3e3fc to 8.5.x. Thanks!