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
Now that #2281635: \Drupal\Core\Plugin\Context\Context should use a ContextDefinition class instead of arrays is in, we shouldn't have to manually create DataDefinition objects.
Proposed resolution
See #2292889-8: ContextHandler does not expect ContextDefinitionInterface
Comments
Comment #1
BerdirThis makes a lot of sense to me and makes the code much easier, getting the unit tests to pass again was not trivial...
- Constraints are now only checked if they are added *explicitly* to the required context of a plugin and not automatically through the typed data type. Those constrains are to validate their internal data, context & and context definition should not care if an entity is valid, it should just care if it matches. Right now, expecting an email for example would require that the provided context also explicitly defines the email constraint, but there is no reason that it has to care about that.
- As a result, removed the @todo related to that, if you now *do* specify a constraint, then it should be checked.
- Removed some unit tests that were testing that
- Updated some others and switched to ContextDefinition (without a mock) instead of mocked DataDefinition objects, also threw out everything typed data related
Comment #2
dawehnerDo we need a change notice for this kind of things?
Maybe we should add a comment like "'any' does always match.".
These changes feel unrelated tbh.
I really like that the API of using the context handler got easier!
Comment #3
BerdirLol, yeah, those changes are completely unrelated, was testing something else...
Comment #4
BerdirRemoved that crap :)
Comment #7
dawehner@berdir
Any oppinions about the comment?
Comment #8
BerdirAh, yes, let's add a comment there.
Comment #9
BerdirLike this?
Comment #10
dawehnerI Like this.
Comment #11
tim.plunkett+1
Comment #12
alexpottI've considered this and I like it too.
Committed 0ede95d and pushed to 8.0.x. Thanks!
Minor clean up on commit.
Comment #14
BerdirClosed #2287061: Not possible to define optional context as a duplicate.
Comment #15
tim.plunkettThanks