entity_id

7 entity.module entity_id($entity_type, $entity)

Returns the entity identifier, i.e. the entities name or numeric id.

Unlike entity_extract_ids() this function returns the name of the entity instead of the numeric id, in case the entity type has specified a name key.

Parameters

$entity_type: The type of the entity.

$entity: An entity object.

See also

entity_extract_ids()

24 calls to entity_id()

197 string references to 'entity_id'

File

contributions/entity/entity.module, line 479
Module file for the entity API.

Code

function entity_id($entity_type, $entity) {
  if (method_exists($entity, 'identifier')) {
    return $entity->identifier();
  }
  $info = entity_get_info($entity_type);
  $key = isset($info['entity keys']['name']) ? $info['entity keys']['name'] : $info['entity keys']['id'];
  return isset($entity->$key) ? $entity->$key : NULL;
}