class VersionByRel in Drupal 9
Same name and namespace in other branches
- 8 core/modules/jsonapi/src/Revisions/VersionByRel.php \Drupal\jsonapi\Revisions\VersionByRel
- 10 core/modules/jsonapi/src/Revisions/VersionByRel.php \Drupal\jsonapi\Revisions\VersionByRel
Revision ID implementation for the default or latest revisions.
@internal JSON:API maintains no PHP API since its API is the HTTP API. This class may change at any time and this will break any dependencies on it.
Hierarchy
- class \Drupal\jsonapi\Revisions\NegotiatorBase implements VersionNegotiatorInterface
- class \Drupal\jsonapi\Revisions\VersionByRel
Expanded class hierarchy of VersionByRel
See also
https://www.drupal.org/project/drupal/issues/3032787
2 files declare their use of VersionByRel
- ResourceObject.php in core/
modules/ jsonapi/ src/ JsonApiResource/ ResourceObject.php - VersionNegotiatorTest.php in core/
modules/ jsonapi/ tests/ src/ Kernel/ Revisions/ VersionNegotiatorTest.php
1 string reference to 'VersionByRel'
- jsonapi.services.yml in core/
modules/ jsonapi/ jsonapi.services.yml - core/modules/jsonapi/jsonapi.services.yml
1 service uses VersionByRel
- jsonapi.version_negotiator.rel in core/
modules/ jsonapi/ jsonapi.services.yml - Drupal\jsonapi\Revisions\VersionByRel
File
- core/
modules/ jsonapi/ src/ Revisions/ VersionByRel.php, line 17
Namespace
Drupal\jsonapi\RevisionsView source
class VersionByRel extends NegotiatorBase {
/**
* Version argument which loads the revision known to be the "working copy".
*
* In Drupal terms, a "working copy" is the latest revision. It may or may not
* be a "default" revision. This revision is the working copy because it is
* the revision to which new work will be applied. In other words, it denotes
* the most recent revision which might be considered a work-in-progress.
*
* @var string
*/
const WORKING_COPY = 'working-copy';
/**
* Version argument which loads the revision known to be the "latest version".
*
* In Drupal terms, the "latest version" is the latest "default" revision. It
* may or may not have later revisions after it, as long as none of them are
* "default" revisions. This revision is the latest version because it is the
* last revision where work was considered finished. Typically, this means
* that it is the most recent "published" revision.
*
* @var string
*/
const LATEST_VERSION = 'latest-version';
/**
* {@inheritdoc}
*/
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);
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
NegotiatorBase:: |
protected | property | The entity type manager to load the revision. | |
NegotiatorBase:: |
protected static | function | Helper method that ensures that a version exists. | |
NegotiatorBase:: |
public | function |
Gets the identified revision. Overrides VersionNegotiatorInterface:: |
|
NegotiatorBase:: |
protected | function | Loads an entity revision. | |
NegotiatorBase:: |
public | function | Constructs a version negotiator instance. | |
VersionByRel:: |
protected | function |
Gets the revision ID. Overrides NegotiatorBase:: |
|
VersionByRel:: |
constant | Version argument which loads the revision known to be the "latest version". | ||
VersionByRel:: |
constant | Version argument which loads the revision known to be the "working copy". |