function _entityreference_feeds_create_entity in Entity reference feeds 7
Helper function for creating entityreference_feeds entities.
Parameters
string $entity_type: The entity type of the entity to be created.
string $bundle: (optional) Name of the bundle of the entity to be created.
array $values: (optional) An array of values as described by the entity's property info. All entity properties of the given entity type that are marked as required, must be present. If the passed values have no matching property, their value will be assigned to the entity directly, without the use of the metadata-wrapper property.
Return value
Entity The created entity or FALSE if the entity could not be created.
1 call to _entityreference_feeds_create_entity()
- entityreference_feeds_entity_presave in ./
entityreference_feeds.module - Implements hook_entity_presave().
File
- ./
entityreference_feeds.module, line 253 - This is the main module file for entity reference feeds.
Code
function _entityreference_feeds_create_entity($entity_type, $bundle = FALSE, $values = array()) {
static $vocabularies = array();
$info = entity_get_info($entity_type);
$default_values = variable_get('entityreference_feeds_entity_default_values', array());
$creation_values = $values + (isset($default_values[$entity_type]['values']) ? array_filter($default_values[$entity_type]['values']) : array());
if (!empty($info['entity keys']['bundle']) && $bundle) {
$creation_values += array(
$info['entity keys']['bundle'] => $bundle,
);
if ($entity_type === 'taxonomy_term') {
// For taxonomy term, add 'vid' property.
if (!isset($vocabularies[$bundle])) {
$vocabulary = taxonomy_vocabulary_machine_name_load($bundle);
$vocabularies[$bundle] = $vocabulary ? $vocabulary->vid : 0;
}
$creation_values['vid'] = $vocabularies[$bundle];
}
}
$entity_wrapper = entity_property_values_create_entity($entity_type, $creation_values);
return $entity_wrapper ? $entity_wrapper
->value() : FALSE;
}