Loads an entity by UUID.
Note that some entity types may not support UUIDs.
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.
EntityInterface|FALSE The entity object, or FALSE if there is no entity with the given UUID.
Drupal\Core\Entity\EntityStorageException Thrown in case the requested entity type does not support UUIDs.
\Drupal\Core\Entity\EntityManager
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 = Drupal::entityManager()
->getStorageController($entity_type);
if ($reset) {
$controller
->resetCache();
}
$entities = $controller
->loadByProperties(array(
$uuid_key => $uuid,
));
return reset($entities);
}