You are here

public function VersionNegotiator::getRevision in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/jsonapi/src/Revisions/VersionNegotiator.php \Drupal\jsonapi\Revisions\VersionNegotiator::getRevision()
  2. 9 core/modules/jsonapi/src/Revisions/VersionNegotiator.php \Drupal\jsonapi\Revisions\VersionNegotiator::getRevision()

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

core/modules/jsonapi/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 {
    [
      $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);
  }
}