0

I have a rule which is triggered upon Event: 'After saving new content'.

My Action involves executing custom php code. Please how can i make the values of the fields of my new node available in my php code.

Thanks.

  • Simply using $node->my_field_name or wrapper=entity_metadata_wrapper('node',$node); $node->field_name->vale(); won't work? If you want to see the actual fields you should update rules to latest version (ffor d7) or add a condition: content is of type – hkoosha Oct 14 '13 at 17:14
1

You can use fields of node currently being added in two ways

  1. Check down the PHP code text field you will find text saying

"The following variables are available and may be used by your PHP code:". Inside this you will get some site variables as $site and node variables as $node.

As per requirement you need fields of current added node so $node is the reference for current added node and also contains the fields you need. Find the screen shot to see how it can be used,as in the example I am using drupal_set_message to show the title of current added node or with first code of line it is simple dpm($node), which will show you complete insight of node once this rule is saved and devel module is installed. enter image description here

  1. Other way is to use tokens replacement options.

Under replacement patterns you will see "Replacement patterns for saved content". This list provides current node fields as toke replacement. Check the screen shot. enter image description here For example usage,if you want to show node title using tokens in rules simply add this code

`drupal_set_message(token_replace('[node:title]', array('node' => $node)));` in the php code.

here in the following screen-shot is a code comparison for the above two ways, you can use any.I usually prefer using $node. enter image description here

0

You can get the values of fields of newly created node from the Replacement patterns available at bottom on "PHP code" of actions as below:

enter image description here

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.