protected function VersionByRel::getRevisionId in JSON:API 8.2
Gets the revision ID.
Parameters
\Drupal\Core\Entity\EntityInterface $entity: The entity.
string $version_argument: A value used to derive a revision ID for the given entity.
Return value
int The revision ID.
Throws
\Drupal\jsonapi\Revisions\VersionNotFoundException When the revision does not exist.
\Drupal\jsonapi\Revisions\InvalidVersionIdentifierException When the revision ID is not valid.
Overrides NegotiatorBase::getRevisionId
File
- src/
Revisions/ VersionByRel.php, line 47
Class
- VersionByRel
- Revision ID implementation for the default or latest revisions.
Namespace
Drupal\jsonapi\RevisionsCode
protected function getRevisionId(EntityInterface $entity, $version_argument) {
assert($entity instanceof RevisionableInterface);
switch ($version_argument) {
case static::WORKING_COPY:
/* @var \Drupal\Core\Entity\RevisionableStorageInterface $entity_storage */
$entity_storage = $this->entityTypeManager
->getStorage($entity
->getEntityTypeId());
return static::ensureVersionExists($entity_storage
->getLatestRevisionId($entity
->id()));
case static::LATEST_VERSION:
// The already loaded revision will be the latest version by default.
// @see \Drupal\Core\Entity\Sql\SqlContentEntityStorage::buildQuery().
return $entity
->getLoadedRevisionId();
default:
$message = sprintf('The version specifier must be either `%s` or `%s`, `%s` given.', static::LATEST_VERSION, static::WORKING_COPY, $version_argument);
throw new InvalidVersionIdentifierException($message);
}
}