public function EntityStorageBase::loadMultiple in Zircon Profile 8.0
Same name and namespace in other branches
- 8 core/lib/Drupal/Core/Entity/EntityStorageBase.php \Drupal\Core\Entity\EntityStorageBase::loadMultiple()
Loads one or more entities.
Parameters
$ids: An array of entity IDs, or NULL to load all entities.
Return value
\Drupal\Core\Entity\EntityInterface[] An array of entity objects indexed by their IDs. Returns an empty array if no matching entities are found.
Overrides EntityStorageInterface::loadMultiple
13 calls to EntityStorageBase::loadMultiple()
- CommentStorage::loadThread in core/
modules/ comment/ src/ CommentStorage.php - To display threaded comments in the correct order we keep a 'thread' field and order by that value. This field keeps this data in a way which is easy to update and convenient to use.
- ConfigEntityStorage::loadMultipleOverrideFree in core/
lib/ Drupal/ Core/ Config/ Entity/ ConfigEntityStorage.php - Loads one or more entities in their original form without overrides.
- EntityStorageBase::load in core/
lib/ Drupal/ Core/ Entity/ EntityStorageBase.php - Loads one entity.
- EntityStorageBase::loadByProperties in core/
lib/ Drupal/ Core/ Entity/ EntityStorageBase.php - Load entities by their property values.
- FieldConfigStorage::loadByProperties in core/
modules/ field/ src/ FieldConfigStorage.php - Load entities by their property values.
2 methods override EntityStorageBase::loadMultiple()
- ContentEntityNullStorage::loadMultiple in core/
lib/ Drupal/ Core/ Entity/ ContentEntityNullStorage.php - Loads one or more entities.
- MigrationStorage::loadMultiple in core/
modules/ migrate/ src/ MigrationStorage.php - Loads one or more entities.
File
- core/
lib/ Drupal/ Core/ Entity/ EntityStorageBase.php, line 224 - Contains \Drupal\Core\Entity\EntityStorageBase.
Class
- EntityStorageBase
- A base entity storage class.
Namespace
Drupal\Core\EntityCode
public function loadMultiple(array $ids = NULL) {
$entities = array();
// Create a new variable which is either a prepared version of the $ids
// array for later comparison with the entity cache, or FALSE if no $ids
// were passed. The $ids array is reduced as items are loaded from cache,
// and we need to know if it's empty for this reason to avoid querying the
// database when all requested entities are loaded from cache.
$passed_ids = !empty($ids) ? array_flip($ids) : FALSE;
// Try to load entities from the static cache, if the entity type supports
// static caching.
if ($this->entityType
->isStaticallyCacheable() && $ids) {
$entities += $this
->getFromStaticCache($ids);
// If any entities were loaded, remove them from the ids still to load.
if ($passed_ids) {
$ids = array_keys(array_diff_key($passed_ids, $entities));
}
}
// Load any remaining entities from the database. This is the case if $ids
// is set to NULL (so we load all entities) or if there are any ids left to
// load.
if ($ids === NULL || $ids) {
$queried_entities = $this
->doLoadMultiple($ids);
}
// Pass all entities loaded from the database through $this->postLoad(),
// which attaches fields (if supported by the entity type) and calls the
// entity type specific load callback, for example hook_node_load().
if (!empty($queried_entities)) {
$this
->postLoad($queried_entities);
$entities += $queried_entities;
}
if ($this->entityType
->isStaticallyCacheable()) {
// Add entities to the cache.
if (!empty($queried_entities)) {
$this
->setStaticCache($queried_entities);
}
}
// Ensure that the returned array is ordered the same as the original
// $ids array if this was passed in and remove any invalid ids.
if ($passed_ids) {
// Remove any invalid ids from the array.
$passed_ids = array_intersect_key($passed_ids, $entities);
foreach ($entities as $entity) {
$passed_ids[$entity
->id()] = $entity;
}
$entities = $passed_ids;
}
return $entities;
}