I wrote a simple rule to change a file field description when it is empty

    { "rules_lab_fix_file_desc" : {
        "LABEL" : "Try to change file description if empty",
        "PLUGIN" : "reaction rule",
        "WEIGHT" : "-10",
        "REQUIRES" : [ "rules" ],
        "ON" : [ "node_presave" ],
        "IF" : [
          { "node_is_of_type" : { "node" : [ "node" ], "type" : { "value" : { "mytype" : "mytype" } } } },
          { "data_is_empty" : { "data" : [ "node:field-file:description" ] } }
        ],
        "DO" : [
          { "data_set" : {
              "data" : [ "node:field-file:description" ],
              "value" : "Bla bla bla."
            }
          }
        ]
      }
    }

but it doesn't work... the rules' log shows that the rule fires as expected but changes simply doesn't affect the string description value.

Adding some dsm() in the rule's action part I've found that the "set a data value" action does its work but the the wrong language :)

dsm($node) before the "set a data value" on node:field-avviso-file:description reports

[...]
$node->field-file['und']['description'] = ''

but after the "set a data value" action the $node contains

[...]
$node->field-file['und']['description'] = ''
$node->field-file['it']['description'] = 'Bla bla bla.'

So it seems to me that rules wrongly sets the value for another language.

Comments

mrfree’s picture

As a temporary workaround I use a PHP action instead of the "set a data value" with something like:
$node->field_file['und'][0]['description'] = "Bla bla bla";

TR’s picture

Category: Bug report » Support request
Status: Active » Postponed (maintainer needs more info)

Is this still an issue? You say "rules wrongly sets the value for another language", but from what I see it doesn't seem to be wrong necessarily. Rules will always operate on the object in the current language. So if your user language is set to 'it' when you edit the node, and the node:language token contains 'it' (you can check that by using a "Show system message" action in your above rule), then the "Set a data value" action will change that version of the node and NOT the 'und' version. This is true for all actions and conditions in Rules. If you want to operate on some other version of the node, or some other language, then you have to do something different.

If that's not the case, and you're still having this problem in the current version of Rules, please export your Rule again, check the node:language token, and describe how you've set up languages on your site. Also explore whether this rule operates differently for users who have different languages set.

TR’s picture

Status: Postponed (maintainer needs more info) » Closed (cannot reproduce)

No further information provided.