You are here

function rules_action_entity_create in Rules 7.2

Action: Create entities.

Related topics

1 string reference to 'rules_action_entity_create'
rules_entity_action_info in modules/entity.rules.inc
Implements hook_rules_action_info() on behalf of the entity module.

File

modules/entity.eval.inc, line 88
Contains rules integration for entities needed during evaluation.

Code

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

      // Remove the parameter name prefix 'param_'.
      $values[substr($name, 6)] = $args[$name];
    }
  }
  try {
    $data = entity_property_values_create_entity($args['type'], $values);
    return array(
      'entity_created' => $data,
    );
  } catch (EntityMetadataWrapperException $e) {
    throw new RulesEvaluationException('Unable to create entity @type": ' . $e
      ->getMessage(), array(
      '@type' => $args['type'],
    ), $element);
  }
}