You are here

public function NegotiatorBase::getRevision in Drupal 9

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

Gets the identified revision.

The JSON:API module exposes revisions in terms of RFC5829. As such, the public API always refers to "versions" and "working copies" instead of "revisions". There are multiple ways to request a specific revision. For example, one might like to load a particular revision by its ID. On the other hand, it may be useful if an HTTP consumer is able to always request the "latest version" regardless of its ID. It is possible to imagine other scenarios as well, like fetching a revision based on a date or time.

Each version negotiator provides one of these strategies and is able to map a version argument to an existing revision.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity for which a revision should be resolved.

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

Return value

\Drupal\Core\Entity\EntityInterface The identified entity revision.

Throws

\Drupal\jsonapi\Revisions\VersionNotFoundException When the revision does not exist.

\Drupal\jsonapi\Revisions\InvalidVersionIdentifierException When the revision ID is invalid.

Overrides VersionNegotiatorInterface::getRevision

File

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

Class

NegotiatorBase
Base implementation for version negotiators.

Namespace

Drupal\jsonapi\Revisions

Code

public function getRevision(EntityInterface $entity, $version_argument) {
  return $this
    ->loadRevision($entity, $this
    ->getRevisionId($entity, $version_argument));
}