You are here

function entity_load in Drupal 8

Same name and namespace in other branches
  1. 7 includes/common.inc \entity_load()

Loads an entity from the database.

Parameters

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

mixed $id: The id of the entity to load.

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

Return value

\Drupal\Core\Entity\EntityInterface|null The entity object, or NULL if there is no entity with the given ID.

Deprecated

in drupal:8.0.0 and is removed from drupal:9.0.0. Use the entity type storage's load() method.

See also

https://www.drupal.org/node/2266845

1 call to entity_load()
EntityLegacyTest::testEntityLegacyCode in core/tests/Drupal/KernelTests/Core/Entity/EntityLegacyTest.php
@expectedDeprecation entity_load_multiple() is deprecated in Drupal 8.0.0 and will be removed before Drupal 9.0.0. Use the entity type storage's loadMultiple() method. See https://www.drupal.org/node/2266845 @expectedDeprecation entity_load() is…
1 string reference to 'entity_load'
SqlContentEntityStorageTest::setUpModuleHandlerNoImplementations in core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageTest.php
Sets up the module handler with no implementations.

File

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

Code

function entity_load($entity_type, $id, $reset = FALSE) {
  @trigger_error('entity_load() is deprecated in Drupal 8.0.0 and will be removed before Drupal 9.0.0. Use the entity type storage\'s load() method. See https://www.drupal.org/node/2266845', E_USER_DEPRECATED);
  $controller = \Drupal::entityManager()
    ->getStorage($entity_type);
  if ($reset) {
    $controller
      ->resetCache([
      $id,
    ]);
  }
  return $controller
    ->load($id);
}