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.
I started with checking existing d7 behaviour:
- assertions are only added in for not negated AND containers and non-negated conditions
- each expression is able to provide assertions via a method. rule expressions opt out of doing so as they are conditionally executed
- action expressions are allowed to provide assertions also, though AFAIK this is unused and I'd not know a use-case for doing that. So it's ok if it works like that, but it does not have to.
I think this makes sense for d8 the same way.
Note that assertions are different from refining context as what is going to change is the state metadata, not the plugins own context metadata. Thus, there has to be a method in addition to refineContextDefinitions(). I'd suggest adding assertMetadata(array $selected_data) on context aware plugins, which is able to modify the passed data definitions.
On the rules engine side, we need to add a method for asserting metadata on the expression plugins also. But as we already have the metadata preparation method, I think plugins can take care of assertions in there and call a protected assertMetadata($metadata_state) helper which handles the logic.
Comments
Comment #2
fagoI started with checking existing d7 behaviour:
- assertions are only added in for not negated AND containers and non-negated conditions
- each expression is able to provide assertions via a method. rule expressions opt out of doing so as they are conditionally executed
- action expressions are allowed to provide assertions also, though AFAIK this is unused and I'd not know a use-case for doing that. So it's ok if it works like that, but it does not have to.
I think this makes sense for d8 the same way.
Note that assertions are different from refining context as what is going to change is the state metadata, not the plugins own context metadata. Thus, there has to be a method in addition to refineContextDefinitions(). I'd suggest adding assertMetadata(array $selected_data) on context aware plugins, which is able to modify the passed data definitions.
On the rules engine side, we need to add a method for asserting metadata on the expression plugins also. But as we already have the metadata preparation method, I think plugins can take care of assertions in there and call a protected assertMetadata($metadata_state) helper which handles the logic.
Comment #3
fagoWIP code at https://github.com/fago/rules/pull/427 - misses test-coverage now.
Comment #4
fagocompleted it and added test coverage. Also opened #2681955: Allow metadata assertions on selected properties as follow-up for clarifying it for selected properties.
Comment #5
fagoand merged!