Problem/Motivation
\Drupal\Core\Plugin\Context\ContextHandlerInterface::applyContextMapping() applies a set of contexts to a given plugin.
If any of the contexts required by the plugin are not present in those passed to the method, an exception is thrown.
However, if the plugin already had that context set, there is no reason to throw the exception
Proposed resolution
If a context is "missing" from those being applied, only throw an exception if the plugin doesn't already have that context
Remaining tasks
User interface changes
API changes
Data model changes
Release notes snippet
| Comment | File | Size | Author |
|---|---|---|---|
| #19 | 3029625-context-19-PASS.patch | 3.2 KB | tim.plunkett |
Comments
Comment #2
tim.plunkettComment #3
tim.plunkettComment #4
tim.plunkettComment #7
tim.plunkettComment #9
fenstratWorks as expected, coming from #3001313: Field blocks in the layout builder do not have view mode suggestions.
Comment #10
alexpottCommitted and pushed 8c90cbfdf7 to 8.8.x and 35ddee690b to 8.7.x. Thanks!
Comment #13
jibranThis commit broke https://www.drupal.org/project/entity_route_context
Comment #14
jibranI see this after updating to beta1.
Comment #15
dpiI dont think the error has to do with the Entity Route Context project directly, in this case the error is caused by a DSfield with an optional context value, which happens to not be satisfied with values. For other pages with the DSField, the context is applied properly without error.
It looks to me like
($context = $plugin->getContext($context_id))from the patch expects either an object or FALSE, but actually it returns an object or throws an exception.We should swallow the exception allowing for the remaining
else/elseif's to execute.Comment #16
dpiShould we continue in this issue?
Kinda ugly patch
Comment #17
jibranA bug fix added a new bug I'd suggest a revert.
Comment #18
tim.plunkettLet's get this reverted.
First have to make sure nothing depends on this change (I can't remember if I landed anything that was blocked on this).
Comment #19
tim.plunkettHere's a fix, and though I really don't like the
continue, it fixes the flow so we can have a try/catch instead of one long if/elseif/elseif/elseif/elseif/elseIdk how I got away with this. I specifically hid the problem with this change...
Comment #20
jibranTagging. Thanks, for the tests and the patch. Fix looks good to me.
Comment #22
jibranLet's commit the follow-up patch then.
Comment #23
jibranComment #24
tim.plunkettLet's do this the right way, and close with a critical follow-up: #3046243: Regression: Optional context values may throw exceptions if unsatisfied