function rules_action_data_set

Action: Modify data.

Related topics

1 string reference to 'rules_action_data_set'
rules_data_action_info in modules/data.rules.inc
Implements hook_rules_action_info() on behalf of the pseudo data module.

File

modules/data.eval.inc, line 15

Code

function rules_action_data_set($wrapper, $value, $settings, $state, $element) {
  if ($wrapper instanceof EntityMetadataWrapper) {
    try {
      // Update the value first then save changes, if possible.
      $wrapper->set($value);
    } catch (EntityMetadataWrapperException $e) {
      throw new RulesEvaluationException('Unable to modify data "@selector": @message', array(
        '@selector' => $settings['data:select'],
        '@message' => $e->getMessage(),
      ));
    }
    // Save changes if a property of a variable has been changed.
    if (strpos($element->settings['data:select'], ':') !== FALSE) {
      $info = $wrapper->info();
      // We always have to save the changes in the parent entity. E.g. when the
      // node author is changed, we don't want to save the author but the node.
      $state->saveChanges(implode(':', explode(':', $settings['data:select'], -1)), $info['parent']);
    }
  }
  else {
    // A not wrapped variable (e.g. a number) is being updated. Just overwrite
    // the variable with the new value.
    return array(
      'data' => $value,
    );
  }
}