function EntityStorageBase::postLoad
Same name in other branches
- 8.9.x core/lib/Drupal/Core/Entity/EntityStorageBase.php \Drupal\Core\Entity\EntityStorageBase::postLoad()
- 10 core/lib/Drupal/Core/Entity/EntityStorageBase.php \Drupal\Core\Entity\EntityStorageBase::postLoad()
- 11.x core/lib/Drupal/Core/Entity/EntityStorageBase.php \Drupal\Core\Entity\EntityStorageBase::postLoad()
Attaches data to entities upon loading.
If there are multiple bundle classes involved, each one gets a sub array with only the entities of the same bundle. If there's only a single bundle, the entity's postLoad() method will get a copy of the original $entities array.
Parameters
array $entities: Associative array of query results, keyed on the entity ID.
3 calls to EntityStorageBase::postLoad()
- ContentEntityStorageBase::loadMultipleRevisions in core/
lib/ Drupal/ Core/ Entity/ ContentEntityStorageBase.php - Loads multiple entity revisions.
- ContentEntityStorageBase::loadUnchanged in core/
lib/ Drupal/ Core/ Entity/ ContentEntityStorageBase.php - Loads an unchanged entity from the database.
- EntityStorageBase::loadMultiple in core/
lib/ Drupal/ Core/ Entity/ EntityStorageBase.php - Loads one or more entities.
File
-
core/
lib/ Drupal/ Core/ Entity/ EntityStorageBase.php, line 411
Class
- EntityStorageBase
- A base entity storage class.
Namespace
Drupal\Core\EntityCode
protected function postLoad(array &$entities) {
$entities_by_class = $this->getEntitiesByClass($entities);
// Invoke entity class specific postLoad() methods. If there's only a single
// class involved, we want to pass in the original $entities array. For
// example, to provide backwards compatibility with the legacy behavior of
// the deprecated user_roles() method, \Drupal\user\Entity\Role::postLoad()
// sorts the array to enforce role weights. We have to let it manipulate the
// final array, not a subarray. However if there are multiple bundle classes
// involved, we only want to pass each one the entities that match.
if (count($entities_by_class) === 1) {
$entity_class = array_key_first($entities_by_class);
$entity_class::postLoad($this, $entities);
}
else {
foreach ($entities_by_class as $entity_class => &$items) {
$entity_class::postLoad($this, $items);
}
}
$this->moduleHandler()
->invokeAllWith('entity_load', function (callable $hook, string $module) use (&$entities) {
$hook($entities, $this->entityTypeId);
});
$this->moduleHandler()
->invokeAllWith($this->entityTypeId . '_load', function (callable $hook, string $module) use (&$entities) {
$hook($entities);
});
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.