A Rules component is saved as config entity. When adding an action to a rule that component should show up in the action plugin selection. The context of that action is the context of the Rules component.

Create a plugin deriver that exposes each Rules component as action or condition plugin.

Comments

klausi created an issue. See original summary.

klausi’s picture

Status: Active » Needs review

Starting at https://github.com/fago/rules/pull/399

no context and provided context yet.

fago’s picture

Status: Needs review » Needs work

good start. added some comments.

klausi’s picture

Status: Needs work » Needs review

context and provided context works.

TODO:
* integrity check, but that depends on #2658944: Integrity check on action and condition plugins, so should probably be a follow-up.
* calculating dependencies in the integrity check, but we don't have that at all yet for anything.
* access checks. Since we don't have #2418165: [META] Rules condition and action plugin access yet also not much we can do now.

Anything else that is missing and should be done?

fago’s picture

Status: Needs review » Needs work

I think having those as todos is fine. But imo at least this should take care of saving changes properly, i.e. postpone auto-saving until the very end of the execution and do not save twice if both component and rule manipulate/autosave the same object.
Besides that it would be nice if we could get away without setting up the whole typed data objects for variables again as I could imagine this becoming a performance issue if one uses many components else.
(added a comment to the PR also)

fago’s picture

Do we have an issue for calculateDependencies()? I've just added RulesComponent::calculateDependencies() as API for modules that want to re-use components in #2671200: Clarify how compenent variables can be provided back.

klausi’s picture

Status: Needs work » Needs review

Implemented a test case to avoid double auto-saving.

I'm wondering if there is a case where a component executed as action has internal variables need to be auto saved that are not visible to the parent in any way? What would be an example for that?

I thought about the entity create action, but it does not do auto saving by itself. Maybe it should?

If an entity is created and then a data value is set on it then it is marked for auto saving. We need to test if that works in a component that is executed as action.

fago’s picture

I thought about the entity create action, but it does not do auto saving by itself. Maybe it should?

Definitely, the provided entity needs auto-saving. If that's not the case, it's a bug as you create an entity and it won't be created ;)

So yeah, I also think that would be a valid example: Have a component which you pass e.g. the node title, and the owner and it creates a node, or a log message (entity). No need to pass the variable back, but it must be saved.

fago’s picture

Status: Needs review » Needs work

reviewed the PR and added some remarks -> nw.
The saving implementation in generally, but in particular the test coverage looks great already!

Besides that, this also misses coverage for conditions. But they are easier as they have no auto-saving and work analogously, so I think they can be a follow-up.

klausi’s picture

Status: Needs work » Needs review

Ready for review again.

The biggest thing left is now provided_context_definitions (as in the PR) vs provided_context (as in 8.x-3.x). I think we should clearly separate the parameters to a component (= context) vs. the provided variables of a component (=provided context). I think it is very confusing to just have a list of context names that point to the context list? I think we should have a clear API that gives you 2 separate lists: the context and the provided context.

fago’s picture

Status: Needs review » Needs work

thanks! added a few more remarks which should be easy to fix - see PR.
As mentioned, the provided context change makes a lot of sense.

klausi’s picture

Status: Needs work » Needs review

Thanks, ready for review again.

klausi’s picture

  • klausi committed 3a0d230 on 8.x-3.x
    Issue #2664700: Expose Rules components as action plugin
    
klausi’s picture

Title: Expose Rules components as action/condition plugin » Expose Rules components as action plugin
Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

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