You are here

protected function NegotiatorBase::loadRevision in Drupal 9

Same name and namespace in other branches
  1. 8 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
Gets the identified revision.

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) {
  $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;
}