Comments

fago created an issue. See original summary.

fago’s picture

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.

fago’s picture

Status: Active » Needs review

WIP code at https://github.com/fago/rules/pull/427 - misses test-coverage now.

fago’s picture

completed it and added test coverage. Also opened #2681955: Allow metadata assertions on selected properties as follow-up for clarifying it for selected properties.

fago’s picture

Status: Needs review » Fixed

and merged!

  • fago committed 2f4d041 on 8.x-3.x
    Issue #2681733 by fago: Improve docs to clarify the difference between...
  • fago committed 7d22771 on 8.x-3.x
    Issue #2681733 by fago: Add metadata assertion support to expressions.
    
  • fago committed 86476df on 8.x-3.x
    Issue #2681733 by fago: Allow context-aware plugins to assert metadata.
    
  • fago committed d95464c on 8.x-3.x
    Issue #2681733 by fago: Improve metadata assertions test coverage.
    
  • fago committed e0ad506 on 8.x-3.x
    Issue #2681733 by fago: Add test coverage for metadata assertions.
    

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.