1 entity.module entity_create_stub_entity($entity_type, $ids)

Assembles an object structure with initial IDs.

This function can be seen as reciprocal to entity_extract_ids().

Parameters

$entity_type: The entity type; e.g. 'node' or 'user'.

$ids: A numerically indexed array, as returned by entity_extract_ids(), containing these elements:

  • 0: Primary ID of the entity.
  • 1: Revision ID of the entity, or NULL if $entity_type is not versioned.
  • 2: Bundle name of the entity, or NULL if $entity_type has no bundles.

Return value

An entity object, initialized with the IDs provided.:

Deprecated

since 1.15.0.

File

core/modules/entity/entity.module, line 492
Entity API for handling entities like nodes or users.

Code

function entity_create_stub_entity($entity_type, $ids) {
  watchdog_deprecated_function('entity', __FUNCTION__);

  $values = array();
  $info = entity_get_info($entity_type);
  $values[$info['entity keys']['id']] = $ids[0];
  if (!empty($info['entity keys']['revision']) && isset($ids[1])) {
    $values[$info['entity keys']['revision']] = $ids[1];
  }
  if (!empty($info['entity keys']['bundle']) && isset($ids[2])) {
    $values[$info['entity keys']['bundle']] = $ids[2];
  }
  return isset($info['entity class']) ? entity_create($entity_type, $values) : (object) $values;
}