3

I have a rule which is triggered when a node is flagged. Currently, the rule loads some content (1) that has been referenced by a field on the flagged content. I have set the rule to create a new piece of content (2) and would like a node reference field on this new piece of content to reference content (1). I know there is a way to do this with PHP but am not sure of it...

Got one more...

I'm now trying to use rules to populate a select list field on a new piece of content. I need the value of the field to be the same as a piece of referenced content that's available to rules. Usually I would use tokens but as its a select list field there is nowhere for me to insert a token. I'm thinking some PHP would do the job, but I don't know where to start.

2

This should actually be pretty simple:

  1. Create your rule for the event "A node has been flagged, under "NAME OF YOUR FLAG" and name your rule
  2. Add an action of "Add new content" and click "Next"
  3. Choose what you want the auto-created content's title to be (w/ or w/out tokens) and select what content type you want created and click "Save"
  4. Add another action of "Populate a field", for the arguments configurations choose "new content type of CONTENT TYPE YOU CREATED" and for field, choose your node reference field and click "Continue"
  5. Again on arguments change to "new content type of CONTENT TYPE YOU CREATED"
  6. Open the fieldset titled: "Advanced: Specify the fields value with PHP code" and enter:

return array(0 => array('nid' => $node->field_NAMEOFYOURFIELD[0]['nid']));

Note: You can find the field names by going to admin/content/types and click "Manage Fields" on the content type you want OR you can do a print_r($node); on a node of that content type to see the node object structure

Now when you view your rule, you should see something like:

Rule Example

and whenever you use that flag, a new node will be created having the same reference as the node you flagged.

  • Hi, thank you so much for your help. Embarrassingly, I can't remember how to find out a field's name in terms of how to reference it with PHP...can you remind me? – Drupal Reggie Feb 23 '12 at 17:17
  • Well you can find the field names by going to admin/content/types and click "Manage Fields" on the content type you want OR you can do a print_r($node); on a node of that content type to see the node object structure – Laxman13 Feb 23 '12 at 17:19
  • Another question if I may...I'm now trying to get rules to create a new piece of content after a node has been flagged. There's a node reference field on the new content and I'd like it to reference the flagged node if possible...more PHP i assume? – Drupal Reggie Feb 23 '12 at 19:46
  • Follow the same steps as above except in 4-5 for the argument, used "flagged node" instead – Laxman13 Feb 23 '12 at 19:55

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.