You are here

function entity_metadata_create_object in Entity API 7

Callback to create entity objects.

1 string reference to 'entity_metadata_create_object'
_entity_info_add_metadata in ./entity.module
Adds metadata and callbacks for core entities to the entity info.

File

modules/callbacks.inc, line 883
Provides various callbacks for the whole core module integration.

Code

function entity_metadata_create_object($values, $entity_type) {
  $info = entity_get_info($entity_type);

  // Make sure at least the bundle and label properties are set.
  if (isset($info['entity keys']['bundle']) && ($key = $info['entity keys']['bundle'])) {
    $values += array(
      $key => NULL,
    );
  }
  if (isset($info['entity keys']['label']) && ($key = $info['entity keys']['label'])) {
    $values += array(
      $key => NULL,
    );
  }
  $entity = (object) $values;
  $entity->is_new = TRUE;
  return $entity;
}