You are here

function entity_id in Entity API 7

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()

10 calls to entity_id()
EntityDefaultUIController::applyOperation in includes/entity.ui.inc
Applies an operation to the given entity.
EntityDefaultUIController::operationFormValidate in includes/entity.ui.inc
Operation form validation callback.
EntityDefaultUIController::overviewTable in includes/entity.ui.inc
Generates the render array for a overview table for arbitrary entities matching the given conditions.
EntityDefaultUIController::overviewTableRow in includes/entity.ui.inc
Generates the row for the passed entity and may be overridden in order to customize the rows.
EntityDrupalWrapper::setEntity in includes/entity.wrapper.inc
Sets the entity internally accepting both the entity id and object.

... See full list

File

./entity.module, line 588

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;
}