You are here

function entity_revision_is_default in Entity API 7

Checks whether the given entity is the default revision.

Note that newly created entities will always be created in default revision, thus TRUE is returned for not yet saved entities.

Parameters

$entity_type: The type of the entity.

$entity: The entity object to check.

Return value

bool A boolean indicating whether the entity is in default revision is returned. If the entity is not revisionable or is new, TRUE is returned.

See also

entity_revision_set_default()

1 call to entity_revision_is_default()
EntityAPIController::deleteRevision in includes/entity.controller.inc
Implements EntityAPIControllerRevisionableInterface::deleteRevision().

File

./entity.module, line 410

Code

function entity_revision_is_default($entity_type, $entity) {
  $info = entity_get_info($entity_type);
  if (empty($info['entity keys']['revision'])) {
    return TRUE;
  }

  // Newly created entities will always be created in default revision.
  if (!empty($entity->is_new) || empty($entity->{$info['entity keys']['id']})) {
    return TRUE;
  }
  if (in_array('EntityAPIControllerRevisionableInterface', class_implements($info['controller class']))) {
    $key = !empty($info['entity keys']['default revision']) ? $info['entity keys']['default revision'] : 'default_revision';
    return !empty($entity->{$key});
  }
  else {

    // Else, just load the default entity and compare the ID. Usually, the
    // entity should be already statically cached anyway.
    $default = entity_load_single($entity_type, $entity->{$info['entity keys']['id']});
    return $default->{$info['entity keys']['revision']} == $entity->{$info['entity keys']['revision']};
  }
}