function VersionNegotiator::getRevision

Same name and namespace in other branches
  1. 8.9.x core/modules/jsonapi/src/Revisions/VersionNegotiator.php \Drupal\jsonapi\Revisions\VersionNegotiator::getRevision()
  2. 10 core/modules/jsonapi/src/Revisions/VersionNegotiator.php \Drupal\jsonapi\Revisions\VersionNegotiator::getRevision()
  3. 11.x 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);
    }
}

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