You are here

public function VersionNegotiator::getRevision in JSON:API 8.2

Gets a negotiated entity revision.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity.

string $resource_version_identifier: A value used to derive a revision for the given entity.

Return value

\Drupal\Core\Entity\EntityInterface The loaded revision.

Throws

\Drupal\Core\Http\Exception\CacheableNotFoundHttpException When the revision does not exist.

\Drupal\Core\Http\Exception\CacheableBadRequestHttpException When the revision ID cannot be negotiated.

File

src/Revisions/VersionNegotiator.php, line 66

Class

VersionNegotiator
Provides a version negotiator manager.

Namespace

Drupal\jsonapi\Revisions

Code

public function getRevision(EntityInterface $entity, $resource_version_identifier) {
  try {
    list($version_negotiator_name, $version_argument) = explode(VersionNegotiator::SEPARATOR, $resource_version_identifier, 2);
    if (!isset($this->negotiators[$version_negotiator_name])) {
      static::throwBadRequestHttpException($resource_version_identifier);
    }
    return $this->negotiators[$version_negotiator_name]
      ->getRevision($entity, $version_argument);
  } catch (VersionNotFoundException $exception) {
    static::throwNotFoundHttpException($entity, $resource_version_identifier);
  } catch (InvalidVersionIdentifierException $exception) {
    static::throwBadRequestHttpException($resource_version_identifier);
  }
}