You are here

function rules_action_data_create in Rules 7.2

Action: Create data.

Related topics

1 string reference to 'rules_action_data_create'
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 288
Contains rules integration for the data module needed during evaluation.

Code

function rules_action_data_create($args, $element) {
  $type = $args['type'];
  $values = array();
  foreach ($element
    ->pluginParameterInfo() as $name => $info) {
    if ($name != 'type') {

      // Remove the parameter name prefix 'param_'.
      $values[substr($name, 6)] = $args[$name];
    }
  }
  $cache = rules_get_cache();
  $type_info = $cache['data_info'][$type];
  if (isset($type_info['creation callback'])) {
    try {
      $data = $type_info['creation callback']($values, $type);
      return array(
        'data_created' => $data,
      );
    } catch (EntityMetadataWrapperException $e) {
      throw new RulesEvaluationException('Unable to create @data": ' . $e
        ->getMessage(), array(
        '@data' => $type,
      ), $element);
    }
  }
  else {
    throw new RulesEvaluationException('Unable to create @data, no creation callback found.', array(
      '@data' => $type,
    ), $element, RulesLog::ERROR);
  }
}