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

5 calls to entity_load_by_uuid()
CustomBlockBlock::build in drupal/core/modules/block/custom_block/lib/Drupal/custom_block/Plugin/Block/CustomBlockBlock.php
Builds and returns the renderable array for this block plugin.
custom_block_form_block_plugin_ui_alter in drupal/core/modules/block/custom_block/custom_block.module
Implements hook_form_FORM_ID_alter() for block_plugin_ui().
EntityUUIDTest::assertCRUD in drupal/core/modules/system/lib/Drupal/system/Tests/Entity/EntityUUIDTest.php
Executes the UUID CRUD tests for the given entity type.
ShortcutStorageController::postSave in drupal/core/modules/shortcut/lib/Drupal/shortcut/ShortcutStorageController.php
Overrides \Drupal\config\ConfigStorageController::postSave().
UuidResolver::resolve in drupal/core/modules/serialization/lib/Drupal/serialization/EntityResolver/UuidResolver.php
Implements \Drupal\serialization\EntityResolver\EntityResolverInterface::resolve().

File

drupal/core/includes/entity.inc, line 225
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 = Drupal::entityManager()
    ->getStorageController($entity_type);
  if ($reset) {
    $controller
      ->resetCache();
  }
  $entities = $controller
    ->loadByProperties(array(
    $uuid_key => $uuid,
  ));
  return reset($entities);
}