Skip to content

Commit

Permalink
Call postLoad() hook by bundle amcgowanca#8
Browse files Browse the repository at this point in the history
  • Loading branch information
simonbaese committed Oct 29, 2018
1 parent 1a9b89c commit 72b0331
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/Storage/SqlContentEntityStorageTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,24 @@ protected function mapFromStorageRecords(array $records, $load_from_revision = F
* {@inheritdoc}
*/
protected function postLoad(array &$entities) {
$entity_class = $this->getEntityClass();
$entity_class::postLoad($this, $entities);
// Call postLoad() by bundle if bundleKey is set.
// Iterate over entities to determine respective bundles because entities
// might are of different types.
if (isset($this->bundleKey)) {
$entities_by_bundle = [];
foreach ($entities as $entity) {
$entities_by_bundle[$entity->get($this->bundleKey)->getString()][] = $entity;
}
foreach ($entities_by_bundle as $bundle => $entities_bundled) {
$entity_class = $this->getEntityClass($bundle);
$entity_class::postLoad($this, $entities_bundled);
}
}
// Call postLoad() by parent entity if it is not bundled.
else {
$entity_class = $this->getEntityClass();
$entity_class::postLoad($this, $entities);
}
// Call hook_entity_load().
foreach ($this->moduleHandler()->getImplementations('entity_load') as $module) {
$function = $module . '_entity_load';
Expand Down

0 comments on commit 72b0331

Please sign in to comment.