Posted by georgwaechter on September 15, 2010 at 1:13pm
Hi,
i try to use a token within a rules action that should copy one cck field value from one node to another. It works perfectly for text fields, but i have a problem with my number fields, because they allow only inputs of a maximum of 10 characters. Enough for all numbers but not for long tokens. Is there a workaround?
Greetings
Georg
Comments
PHP...
The workaround I'm usually using is to have PHP filter active (core module) and use the following PHP snippet:
return ($source_node->field_source_field);It is bad practice to keep PHP code in configuration, for several reasons, but this works.
Good luck!
//Johan Falk, NodeOne, Sweden
PS: I am dreaming of creating a Rules Bonus Pack module, or something like that, with a number of extra Rules actions included. One of them would be 'Copy value(s) between fields', and would do this for just about any type of CCK field. The actions that are appreciated and stable enough would be committed to their respective projects (CCK in this case), while the bonus pack module continues to be a greenhouse for new ideas.
Unfortunately I can't really code, and I have only just started looking into how to code Rules actions.
return
return ($source_node->field_source_field);this you use on a cck field that take value by one other cck field?
the code is insert in the php allowed value of a cck's field with wideget select list?
which is the correct code to use?
field_source_field think is really to be write so field_yourname[0]['value'];
and $source_node how is write?
think is necessary to use a variable that can to read the variable(argument node) that is used
every time
Using with Rules
It is not 100% clear in the start post, but this issue relates to using the Rules module to populate a CCK field.
When doing so, and the PHP filter module is enabled, there is a place for entering PHP to use to populate the field. If using that field, you can call available variables and objects, and use their properties to set the field you want to populate.
I don't really understand what you are asking in the comment above, so my advice is this:
Good luck!
//Johan Falk, NodeOne, Sweden
Let's say that you need to do
Let's say that you need to do this for 10 different CCK fields on a given node. Would it be possible to accomplish this with one 'Execute a PHP Script' action rather than adding 10 separate 'Populate a CCK field' actions and writing a script for each one? What form would the return have to take?
There is now a better way!
A few days ago I started to work on Rules Bonus Pack. It's a module with a number of new actions and conditions, and among these is the option to set a CCK field without the limitations of the field's widget – you just paste a token value into a text field.
If you still want to do this with custom PHP, I suggest using the "execute custom PHP" action and do something like this:
$node->field_text[0]['value'] = 'value one';
$node->field_nodereference[0]['nid'] = 2;
$node->field_integer[0]['value'] = 'value three';
$node->field_text_multiple[0]['value'] = '4a';
$node->field_text_multiple[1]['value'] = '4b';
return array(
'node' => $node,
);
The name of the variable ($node) may be different, but you should have a help box showing you the right names.
I have probably said this a thousand times already, but I really discourage using PHP as part of configuration. It is slow, insecure and difficult to manage.
Good luck!
//Johan Falk
**
Learn Drupal with Nodeone! Drupal 7 introduction | The Views module | Learn Page manager! | Drupal configuration learning curve | Rules for Drupal 6 | Theming Drupal 6 | 49 Drupal 6 modules you should know