function entity_load_by_uuid

Loads an entity by UUID.

Note that some entity types may not support UUIDs.

Parameters

string $entity_type: The entity type to load; e.g., 'node' or 'user'.

string $uuid: The UUID of the entity to load.

bool $reset: Whether to reset the internal cache for the requested entity type.

Return value

EntityInterface|FALSE The entity object, or FALSE if there is no entity with the given UUID.

Throws

Drupal\Core\Entity\EntityStorageException Thrown in case the requested entity type does not support UUIDs.

See also

\Drupal\Core\Entity\EntityManager

1 call to entity_load_by_uuid()
EntityUUIDTest::testCRUD in drupal/core/modules/system/lib/Drupal/system/Tests/Entity/EntityUUIDTest.php
Tests UUID generation in entity CRUD operations.

File

drupal/core/includes/entity.inc, line 147
Entity API for handling entities like nodes or users.

Code

function entity_load_by_uuid($entity_type, $uuid, $reset = FALSE) {
  $entity_info = entity_get_info($entity_type);
  if (empty($entity_info['entity_keys']['uuid'])) {
    throw new EntityStorageException("Entity type {$entity_type} does not support UUIDs.");
  }
  $uuid_key = $entity_info['entity_keys']['uuid'];
  $controller = entity_get_controller($entity_type);
  if ($reset) {
    $controller
      ->resetCache();
  }
  $entities = $controller
    ->loadByProperties(array(
    $uuid_key => $uuid,
  ));
  return reset($entities);
}