function NegotiatorBase::loadRevision

Same name in other branches
  1. 9 core/modules/jsonapi/src/Revisions/NegotiatorBase.php \Drupal\jsonapi\Revisions\NegotiatorBase::loadRevision()
  2. 8.9.x core/modules/jsonapi/src/Revisions/NegotiatorBase.php \Drupal\jsonapi\Revisions\NegotiatorBase::loadRevision()
  3. 10 core/modules/jsonapi/src/Revisions/NegotiatorBase.php \Drupal\jsonapi\Revisions\NegotiatorBase::loadRevision()

Loads an entity revision.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity for which to load a revision.

int $revision_id: The revision ID to be loaded.

Return value

\Drupal\Core\Entity\EntityInterface|null The revision or NULL if the revision does not exists.

Throws

\Drupal\Component\Plugin\Exception\PluginNotFoundException Thrown if the entity type doesn't exist.

\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException Thrown if the storage handler couldn't be loaded.

1 call to NegotiatorBase::loadRevision()
NegotiatorBase::getRevision in core/modules/jsonapi/src/Revisions/NegotiatorBase.php

File

core/modules/jsonapi/src/Revisions/NegotiatorBase.php, line 77

Class

NegotiatorBase
Base implementation for version negotiators.

Namespace

Drupal\jsonapi\Revisions

Code

protected function loadRevision(EntityInterface $entity, $revision_id) {
    
    /** @var \Drupal\Core\Entity\RevisionableStorageInterface $storage */
    $storage = $this->entityTypeManager
        ->getStorage($entity->getEntityTypeId());
    $revision = static::ensureVersionExists($storage->loadRevision($revision_id));
    if ($revision->id() !== $entity->id()) {
        throw new VersionNotFoundException(sprintf('The requested resource does not have a version with ID %s.', $revision_id));
    }
    return $revision;
}

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