function entity_load_multiple in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/includes/entity.inc \entity_load_multiple()
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 "controllers['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::entityManager()
->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\EntityManagerInterface::getStorage()
\Drupal\Core\Entity\EntityStorageInterface::loadMultiple()
\Drupal\Core\Entity\Sql\SqlContentEntityStorage
\Drupal\Core\Entity\Query\QueryInterface
14 calls to entity_load_multiple()
- BulkDeleteTest::setUp in core/
modules/ field/ src/ Tests/ BulkDeleteTest.php - Set the default field storage backend for fields created during tests.
- CsrfTest::testCookieAuth in core/
modules/ rest/ src/ Tests/ CsrfTest.php - Tests that CSRF check is triggered for Cookie Auth requests.
- DefaultSelection::getReferenceableEntities in core/
lib/ Drupal/ Core/ Entity/ Plugin/ EntityReferenceSelection/ DefaultSelection.php - Gets the list of referenceable entities.
- editor_load in core/
modules/ editor/ editor.module - Loads an individual configured text editor based on text format ID.
- EntityApiTest::assertCRUD in core/
modules/ system/ src/ Tests/ Entity/ EntityApiTest.php - Executes a test set for a defined entity type and user.
File
- core/
includes/ entity.inc, line 182 - 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);
}