You are here

function entity_uuid_delete in Universally Unique IDentifier 7

Permanently delete the given entity by its UUID.

This function depends on the Entity API module to provide the 'entity_delete()' function.

See also

entity_delete()

Related topics

5 calls to entity_uuid_delete()
UUIDCommentTestCase::testCommentCrud in ./uuid.test
Test CRUD on comments with UUID functions.
UUIDNodeTestCase::testNodeCrud in ./uuid.test
Tests CRUD on nodes with UUID functions.
UUIDTaxonomyTestCase::testTaxonomyCrud in ./uuid.test
Test CRUD on comments with UUID functions.
UUIDUserTestCase::testUserCrud in ./uuid.test
Test CRUD on users with UUID functions.
_uuid_services_entity_delete in uuid_services/uuid_services.module
Callback for the 'delete' method.
1 string reference to 'entity_uuid_delete'
uuid_hook_info in ./uuid.module
Implements hook_hook_info().

File

./uuid.entity.inc, line 355
Entity related functions for UUID module.

Code

function entity_uuid_delete($entity_type, $uuid) {

  // This function, and this function only, depends on the entity module.
  if (!module_exists('entity')) {
    throw new UuidEntityException(t('Calling %function requires the Entity API module (!link).', array(
      '%function' => __FUNCTION__,
      '!link' => 'http://drupal.org/project/entity',
    )));
  }
  $info = entity_get_info($entity_type);
  if (isset($info['uuid']) && $info['uuid'] == TRUE) {

    // Fetch the local ID by its UUID.
    $ids = entity_get_id_by_uuid($entity_type, array(
      $uuid,
    ));
    $id = reset($ids);
    $entity = entity_load($entity_type, array(
      $id,
    ));

    // Let other modules transform UUID references to local ID references.
    $hook = 'entity_uuid_delete';
    foreach (module_implements($hook) as $module) {
      $function = $module . '_' . $hook;
      if (function_exists($function)) {
        $function($entity, $entity_type);
      }
    }
    if (empty($entity)) {
      return FALSE;
    }

    // Delete the entity.
    return entity_delete($entity_type, $id);
  }
  else {
    throw new UuidEntityException(t("Trying to delete a @type entity, which doesn\\'t support UUIDs.", array(
      '@type' => $info['label'],
    )));
  }
}