function ContentEntityStorageBase::loadMultipleRevisions

Same name in other branches
  1. 9 core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php \Drupal\Core\Entity\ContentEntityStorageBase::loadMultipleRevisions()
  2. 8.9.x core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php \Drupal\Core\Entity\ContentEntityStorageBase::loadMultipleRevisions()
  3. 10 core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php \Drupal\Core\Entity\ContentEntityStorageBase::loadMultipleRevisions()

Overrides RevisionableStorageInterface::loadMultipleRevisions

1 call to ContentEntityStorageBase::loadMultipleRevisions()
ContentEntityStorageBase::loadRevision in core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php
Loads a specific entity revision.
1 method overrides ContentEntityStorageBase::loadMultipleRevisions()
ContentEntityNullStorage::loadMultipleRevisions in core/lib/Drupal/Core/Entity/ContentEntityNullStorage.php
Loads multiple entity revisions.

File

core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php, line 642

Class

ContentEntityStorageBase
Base class for content entity storage handlers.

Namespace

Drupal\Core\Entity

Code

public function loadMultipleRevisions(array $revision_ids) {
    $revisions = $this->doLoadMultipleRevisionsFieldItems($revision_ids);
    // The hooks are executed with an array of entities keyed by the entity ID.
    // As we could load multiple revisions for the same entity ID at once we
    // have to build groups of entities where the same entity ID is present only
    // once.
    $entity_groups = [];
    $entity_group_mapping = [];
    foreach ($revisions as $revision) {
        $entity_id = $revision->id();
        $entity_group_key = isset($entity_group_mapping[$entity_id]) ? $entity_group_mapping[$entity_id] + 1 : 0;
        $entity_group_mapping[$entity_id] = $entity_group_key;
        $entity_groups[$entity_group_key][$entity_id] = $revision;
    }
    // Invoke the entity hooks for each group.
    foreach ($entity_groups as $entities) {
        $this->invokeStorageLoadHook($entities);
        $this->postLoad($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 ($revision_ids) {
        $flipped_ids = array_intersect_key(array_flip($revision_ids), $revisions);
        $revisions = array_replace($flipped_ids, $revisions);
    }
    return $revisions;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.