8.5.x entity.inc entity_load($entity_type, $id, $reset = FALSE)
8.0.x entity.inc entity_load($entity_type, $id, $reset = FALSE)
8.1.x entity.inc entity_load($entity_type, $id, $reset = FALSE)
8.2.x entity.inc entity_load($entity_type, $id, $reset = FALSE)
8.3.x entity.inc entity_load($entity_type, $id, $reset = FALSE)
8.4.x entity.inc entity_load($entity_type, $id, $reset = FALSE)
8.6.x entity.inc entity_load($entity_type, $id, $reset = FALSE)
7.x common.inc entity_load($entity_type, $ids = FALSE, $conditions = array(), $reset = FALSE)

Loads an entity from the database.

\Drupal::entityTypeManager()
  ->getStorage($entity_type)
  ->load($id);

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.x, will be removed before Drupal 9.0.0. Use The method overriding Entity::load() for the entity type, e.g. \Drupal\node\Entity\Node::load() if the entity type is known. If the entity type is variable, use the entity manager service to load the entity from the entity storage:

See also

\Drupal\Core\Entity\EntityInterface::load()

\Drupal\Core\Entity\EntityTypeManagerInterface::getStorage()

\Drupal\Core\Entity\EntityStorageInterface::load()

\Drupal\Core\Entity\Sql\SqlContentEntityStorage

\Drupal\Core\Entity\Query\QueryInterface

8 calls to entity_load()
ConfigEntityNormalizeTest::testNormalize in core/tests/Drupal/KernelTests/Core/Config/ConfigEntityNormalizeTest.php
ConfigEntityStatusTest::testCRUD in core/tests/Drupal/KernelTests/Core/Config/ConfigEntityStatusTest.php
Tests the enabling/disabling of entities.
ConfigEntityStatusUITest::testCRUD in core/modules/config/src/Tests/ConfigEntityStatusUITest.php
Tests status operations.
ConfigEntityStorageTest::testUUIDConflict in core/tests/Drupal/KernelTests/Core/Config/ConfigEntityStorageTest.php
Tests creating configuration entities with changed UUIDs.
ConfigEntityTest::testCRUDUI in core/modules/config/src/Tests/ConfigEntityTest.php
Tests CRUD operations through the UI.

... See full list

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 80
Entity API for handling entities like nodes or users.

Code

function entity_load($entity_type, $id, $reset = FALSE) {
  $controller = \Drupal::entityManager()
    ->getStorage($entity_type);
  if ($reset) {
    $controller
      ->resetCache(array(
      $id,
    ));
  }
  return $controller
    ->load($id);
}

Comments

frankherrman’s picture

The $id parameter cannot be false anymore like in Drupal 7. As the deprecation warning is showing you should override the Entity::load() method. If you want to load all entities from a specific type from a different module, use:

$entity_manager = \Drupal::entityManager();
$users = $entity_manager->getStorage('users')->loadMultiple(false);
robpowell’s picture

$entity_manager = \Drupal::entityManager();

entityManager is now depreciated in favor of entityTypeManager, https://api.drupal.org/api/drupal/core!lib!Drupal.php/function/Drupal%3A....

Here is an example of how I am loading a single node:

$entity_manager = \Drupal::entityTypeManager();
$node = $entity_manager->getStorage('node')->load($nid);