You are here

function entity_load_multiple in Drupal 8

Loads multiple entities from the database.

This function should be used whenever you need to load more than one entity from the database. The entities are loaded into memory and will not require database access if loaded again during the same page request.

The actual loading is done through a class that has to implement the \Drupal\Core\Entity\EntityStorageInterface interface. By default, \Drupal\Core\Entity\Sql\SqlContentEntityStorage is used for content entities and Drupal\Core\Config\Entity\ConfigEntityStorage for config entities. Entity types can specify that a different class should be used by setting the "handlers['storage']" key in the entity plugin annotation. These classes can either implement the \Drupal\Core\Entity\EntityStorageInterface interface, or, most commonly, extend the \Drupal\Core\Entity\Sql\SqlContentEntityStorage class. See \Drupal\node\Entity\Node and \Drupal\node\NodeStorage for an example.

Parameters

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

array $ids: (optional) An array of entity IDs. If omitted, all entities are loaded.

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

Return value

array An array of entity objects indexed by their IDs.

Deprecated

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

See also

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

1 call to entity_load_multiple()
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…

File

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

Code

function entity_load_multiple($entity_type, array $ids = NULL, $reset = FALSE) {
  @trigger_error('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', E_USER_DEPRECATED);
  $controller = \Drupal::entityManager()
    ->getStorage($entity_type);
  if ($reset) {
    $controller
      ->resetCache($ids);
  }
  return $controller
    ->loadMultiple($ids);
}