function EntityConverter::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.

Deprecated

in drupal:8.7.0 and is removed from drupal:9.0.0.

File

core/lib/Drupal/Core/ParamConverter/EntityConverter.php, line 201

Class

EntityConverter
Parameter converter for upcasting entity IDs to full objects.

Namespace

Drupal\Core\ParamConverter

Code

protected function loadRevision(RevisionableInterface $entity, $revision_id) {
  @trigger_error('\\Drupal\\Core\\ParamConverter\\EntityConverter::loadRevision() is deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0.', E_USER_DEPRECATED);
  // 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);
  }
  else {
    return $entity;
  }
}

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