entity_load_multiple

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

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);
}
doc_Drupal
2016-10-29 09:09:15
Comments
Leave a Comment

Please login to continue.