Active
Project:
Rules
Version:
7.x-2.x-dev
Component:
Rules Core
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
2 Mar 2012 at 11:34 UTC
Updated:
31 Jan 2013 at 14:47 UTC
I have an action that provides me with a file entity, and I would like to the set the file entity as the value of node:field_image.
However, It seems I can only set it as the value of node:field_image:file . This works fine if the field has a value at the start of the rule, but fails if it doesn't. I can't set the value of the whole field.
Is this a bug? or am I doing it wrong?
Comments
Comment #1
OnkelTem commentedI confirm this.
I have a loop in which I use data_set action to set custom field of type Image to some image. If there were no images, then nothing is set.
UPDATE
I figured out the reason hitting my special case since I was creating images on Commerce Products, not nodes.
Comment #2
dynamicdan commentedI've just run into this problem and I think I know why it doesn't work...
I have an integer field that I'm trying to set a value using php: "return time();". The field in drupal has a default value of 0 when creating NEW content items. The old ones have no value (equivalent to NULL I guess). The rules module probably doesn't get any value to process when trying to save the item and therefore $value (the available var) is probably NULL.
It could however also be failing the field condition ("entity must have field"). I haven't debugged that far yet but the problem is definitely there and should be obvious to a maintainer/fixer.
Note that I expected to return "return array('und'=>array('value'=> time() ));" but I guess Rules/Entity tries to be smarter than that???
For new nodes I'm guessing the default array structure is something like "$node->field_published_date = array()". Perhaps no value can be obtained by Rules when it's like this.
Comment #3
David Stosik commentedHello,
dynamicdan> sorry but I can't reproduce your bug with a simple text field, even when multiple.
But rlmumford, I can reproduce your bug.
An image field consists in an file entity, but it is not enough. Thus, when trying to set node:field_image:file on a node which image field is already set, it works, and the the node's image field get the wanted image.
On the other hand, if you try to set node:field_image:file on a node where no image was set, then it doesn't work and produces the notice:
On the other way, setting node:field_image using another field_image (from another node, for example) works perfectly.
I would say it is node a bug, but a limitation due to the way Rules is coded. Requesting for a way, in Rules, to initialize a field (whatever the field), properly, sounds appropriate.
Regards,
David