1

I have a node that has a node reference to another content type. What I want is to update the referenced node field value on updating the node;

Let me clarify the issue.

For example I have a node of type "Basic Page" which having a relationship to a node of type "Article". I want to sync fields in two node let say I have a name field(Text) in both nodes. On updating basic page node I want to populate the referenced node Name field with that of the value in the basic page node Name field. How can I do that?

This is what I have done so far:

  1. Event - After updating existing content.
  2. Condition - Content is of type Basic page.
  3. Action - Fetch entity by id(id from the entity reference field).
  4. Action - Set a data value .

I am stuck at the fourth step I can't select the name field of the entity fetched in the data selector.

How can I populate the referenced node field with the value of the blog page node field?

Note: This is just for example In real case I want to map multiple fields from one node to another.

This is the exported rule:

{ "rules_on_updating_basic_page_nodes" : {
    "LABEL" : "On updating Basic Page nodes",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules" ],
    "ON" : { "node_update" : [] },
    "IF" : [
      { "node_is_of_type" : { "node" : [ "node" ], "type" : { "value" : { "page" : "page" } } } }
    ],
    "DO" : [
      { "entity_fetch" : {
          "USING" : { "type" : "node", "id" : [ "node:field-article:nid" ] },
          "PROVIDE" : { "entity_fetched" : { "entity_fetched" : "Fetched entity" } }
        }
      }
    ]
  }
}
1

You have to add a Condition to the rule of the class: "Entity has field", and then a whole bunch of the referenced fields of the entity will appear.

0

You will need to make it call a Rule Component as you need to specify conditions before the available options in the Rules interface will be available.

As you're fetching an entity these options won't be available.

  • What you meant by "call a Rule Component". Is there any solution to make it work. I found a solution by adding custom PHP code inside the rule action for loading a node and make the changes and then saving it, all this is done by manual coding. Is that the only solution? Is there any alternative method? – Jetson John Oct 20 '14 at 16:30
  • Components are stand-alone Rules configuration that can be called from reaction rules, other modules and also programmatically from custom code drupal.org/node/1300024 – Colin Shipton Oct 21 '14 at 19:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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