| 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.
$entity_type: The type of the entity.
$entity: An entity object.
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;
}