You are here

function entity_save in Entity API 7

Permanently save an entity.

In case of failures, an exception is thrown.

Parameters

$entity_type: The type of the entity.

$entity: The entity to save.

Return value

int|false For entity types provided by the CRUD API, SAVED_NEW or SAVED_UPDATED is returned depending on the operation performed. If there is no information how to save the entity, FALSE is returned.

See also

entity_type_supports()

8 calls to entity_save()
EntityAPITestCase::testCRUDAPIfunctions in ./entity.test
Tests CRUD API functions: entity_(create|delete|save)
EntityAPITestCase::testCRUDRevisisions in ./entity.test
Tests CRUD for entities supporting revisions.
EntityDefaultUIController::applyOperation in includes/entity.ui.inc
Applies an operation to the given entity.
EntityDrupalWrapper::save in includes/entity.wrapper.inc
Permanently save the wrapped entity.
EntityMetadataIntegrationTestCase::testCRUDfunctions in ./entity.test
Runs some generic tests on each entity.

... See full list

File

./entity.module, line 288

Code

function entity_save($entity_type, $entity) {
  $info = entity_get_info($entity_type);
  if (method_exists($entity, 'save')) {
    return $entity
      ->save();
  }
  elseif (isset($info['save callback'])) {
    $info['save callback']($entity);
  }
  elseif (in_array('EntityAPIControllerInterface', class_implements($info['controller class']))) {
    return entity_get_controller($entity_type)
      ->save($entity);
  }
  else {
    return FALSE;
  }
}