8.2.x entity.inc entity_load_multiple($entity_type, array $ids = NULL, $reset = FALSE)
8.0.x entity.inc entity_load_multiple($entity_type, array $ids = NULL, $reset = FALSE)
8.1.x entity.inc entity_load_multiple($entity_type, array $ids = NULL, $reset = FALSE)
8.3.x entity.inc entity_load_multiple($entity_type, array $ids = NULL, $reset = FALSE)

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.

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

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.x, will be removed before Drupal 9.0.0. Use The method overriding Entity::loadMultiple() for the entity type, e.g. \Drupal\node\Entity\Node::loadMultiple() 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::loadMultiple()

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

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

\Drupal\Core\Entity\Sql\SqlContentEntityStorage

\Drupal\Core\Entity\Query\QueryInterface

1 call to entity_load_multiple()
editor_file_download in core/modules/editor/editor.module
Implements hook_file_download().

File

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

Code

function entity_load_multiple($entity_type, array $ids = NULL, $reset = FALSE) {
  $controller = \Drupal::entityManager()->getStorage($entity_type);
  if ($reset) {
    $controller->resetCache($ids);
  }
  return $controller->loadMultiple($ids);
}

Comments

MKorostoff’s picture

So, for instance, if you wanted to load all the nodes of the type "article" you would do:

$query = \Drupal::entityQuery('node');
$query->condition('status', 1);
$query->condition('type', 'todo');
$entity_ids = $query->execute();
$nodes = \Drupal::entityTypeManager()->getStorage('node')->loadMultiple($entity_ids);
JeroenT’s picture

Or even shorter:

$nodes = \Drupal::entityTypeManager()->getStorage('node')->loadByProperties(['type' => 'page']);