1

My problem is as follows:

  • I have a taxonomy vocabulary with terms, which are changing from time to time.
  • I have two node types --> type 1 and type 2
  • Type 1 has a taxonomy term reference field
  • Type 2 has an entity reference field which can be prepopulated with the module "entity reference prepopulate"

If I create a new node of node type type 1 then a rule should check which terms are selected and create a new node of type 2 for each selected term automatically.

The entity reference field of the new type 2 node should be prepopulated with a reference back to the original type 1 node.

Because the terms of the vocabulary are changing, the check up by the rule should be IMHO dynamic.

Dummy-Code:

If a new node of node type 1 is saved,then check which taxonomy terms are selected.

for each selected term:

  • create a new node of type 2
  • and prepopulate the entity reference field of node type 2 with the value of node type 1.

I tried it with the Conditional Rules module, but there seems no for..each control loop available.

How can I solve my problem?

1 Answer 1

1

If a new node of node type 1 is saved,

= Rules Event: After saving content, of type "type 1".

then check which taxonomy terms are selected.

= Rules Action: Create a Rules loop, which iterates over each of the selected taxonomy terms, assume you use a name for each list item like "selected_term".

for each selected term:

= Rules Action (which is part of the loop), in which you perform a "Rules Component", and which uses as parameter the "selected_term".

  • create a new node of type 2

= 1st Rules Action performed as part of the Rules Component, which is to "Create an entity" (a node of "type 2").

  • and prepopulate the entity reference field of node type 2 with the value of node type 1.

= 2nd Rules Action performed as part of the Rules Component, which is to "set a data value", for the entity reference field, as part of the entity (node) that got created in the previous Rules Action, and followed by a Rules Action to "save the entity".

Refer to the List and loops video for more details about processing lists and loops via Rules.

Note: no need for the Conditional Rules module ...

2
  • Thank you, I didn't understand that a loop in this case is similar to for..each in other programming languages. The video link helped me very much :)
    – dercheffe
    Oct 6, 2017 at 13:52
  • merci (oeps: thank you) for the accept, and +1! Rules is great, but there are a few things (such as lists and loops) that aren't obvious to get used to. Actually I also first learned about it via that very same video link I added. Next question? Possibly also about Rules ... Oct 6, 2017 at 13:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.