function entity_create_stub_entity

entity_create_stub_entity($entity_type, $ids)

Helper function to assemble 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().

Return value

An entity structure, initialized with the ids provided.

See also

entity_extract_ids()

File

includes/common.inc, line 7935
Common functions that many Drupal modules will need to reference.

Code

function entity_create_stub_entity($entity_type, $ids) {
  $entity = new stdClass();
  $info = entity_get_info($entity_type);
  $entity->{$info['entity keys']['id']} = $ids[0];
  if (!empty($info['entity keys']['revision']) && isset($ids[1])) {
    $entity->{$info['entity keys']['revision']} = $ids[1];
  }
  if (!empty($info['entity keys']['bundle']) && isset($ids[2])) {
    $entity->{$info['entity keys']['bundle']} = $ids[2];
  }
  return $entity;
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/includes!common.inc/function/entity_create_stub_entity/7.x