Dear all,

Is there a way to set the value of a variable added by rules using the "Add a variable" action, with the "Execute custom PHP code" action.
I can access the variable but I need to change the value.
Any idea how to do that.

Thank you in advance.

Comments

phazerz’s picture

I second that !

I thought I could "output" my custom PHP code in an added variables but apprently it don't..

Thank you in advance too.

tuccio’s picture

Try creating a global variable in the php action and then retrieve that global variable in the variable assignment php evaluation.

rbrownell’s picture

Did you ever get this figured out?

rbrownell’s picture

Not sure if this helps but you can use PHP to generate the output of the "Add a variable" action (for text).

candelas’s picture

@rbrownell thanks
i was hours looking for this and this way it works. i could pass an nodes array saying that the variable was a text. i was trying to do it with a variable list of nodes and, there, there was not a a php evaluation.
now i can continue :)

rbrownell’s picture

Rules is very specific with what field types can have PHP evaluation. Much to my frustration it seems to only allows for text to have embedded php evaluation. Other field types like numbers, dates and integers and lists you can't perform any php evaluation. There is however a way to convert text into a list using Rules Data Transformations... After working with it for the last four months I must say Rules is not for the faint of heart.

brendanrjohn’s picture

My solution may not apply in all cases, but I created a field with the relevent data type and hid it from display on the form and on the node display. I could set the value of this field using custom php and then use the data in subsequent actions.

lolandese’s picture

Issue summary: View changes

A new helper module might be the solution for some here. See https://www.drupal.org/project/rules_set_site_variables.

delacosta456’s picture

Hi (it tooks me hours too)

For more precision in case anyone confuse like me..(it may help)

Add an "Action" of variable of type text .. --save
Add an "Action" and choose the variable you just added above..
For the Value , switch to direct input and write your php avaluation code inside .... like like shown below AND IMPORTANT MAKE SURE AT THE END YOU RETURN NECAESSRY VARIABLE :

return $yourvarible;

Example

$yourvariable= all what you want..;
more__codeline...more__codeline... more__codeline... 
...
..
return $yourvariable;
TR’s picture

Version: 7.x-2.2 » 7.x-2.x-dev
Status: Active » Fixed

This seems to have been answered by #9.

Status: Fixed » Closed (fixed)

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