function EntityRepository::loadRevision

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

Loads the specified entity revision.

Parameters

\Drupal\Core\Entity\RevisionableInterface $entity: The default revision of the entity being converted.

string $revision_id: The identifier of the revision to be loaded.

Return value

\Drupal\Core\Entity\RevisionableInterface An entity revision object.

1 call to EntityRepository::loadRevision()
EntityRepository::getLatestTranslationAffectedRevision in core/lib/Drupal/Core/Entity/EntityRepository.php
Returns the latest revision translation of the specified entity.

File

core/lib/Drupal/Core/Entity/EntityRepository.php, line 299

Class

EntityRepository
Provides several mechanisms for retrieving entities.

Namespace

Drupal\Core\Entity

Code

protected function loadRevision(RevisionableInterface $entity, $revision_id) {
    // We explicitly perform a loose equality check, since a revision ID may be
    // returned as an integer or a string.
    if ($entity->getLoadedRevisionId() != $revision_id) {
        
        /** @var \Drupal\Core\Entity\RevisionableStorageInterface $storage */
        $storage = $this->entityTypeManager
            ->getStorage($entity->getEntityTypeId());
        return $storage->loadRevision($revision_id);
    }
    return $entity;
}

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