class VersionByRel extends NegotiatorBase (View source)

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.
 

Revision ID implementation for the default or latest revisions.

Constants

WORKING_COPY

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.

LATEST_VERSION

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.

Properties

protected EntityTypeManagerInterface $entityTypeManager

The entity type manager to load the revision.

from  NegotiatorBase

Methods

__construct(EntityTypeManagerInterface $entity_type_manager)

Constructs a version negotiator instance.

int
getRevisionId(EntityInterface $entity, string $version_argument)

Gets the revision ID.

getRevision(EntityInterface $entity, string $version_argument)

Gets the identified revision.

loadRevision(EntityInterface $entity, int $revision_id)

Loads an entity revision.

static int|EntityInterface
ensureVersionExists(int|EntityInterface $revision)

Helper method that ensures that a version exists.

Details

__construct(EntityTypeManagerInterface $entity_type_manager)

Constructs a version negotiator instance.

Parameters

EntityTypeManagerInterface $entity_type_manager

The entity type manager.

protected int getRevisionId(EntityInterface $entity, string $version_argument)

Gets the revision ID.

Parameters

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.

Exceptions

VersionNotFoundException
InvalidVersionIdentifierException

EntityInterface getRevision(EntityInterface $entity, string $version_argument)

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

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

EntityInterface

The identified entity revision.

Exceptions

VersionNotFoundException
InvalidVersionIdentifierException

protected EntityInterface|null loadRevision(EntityInterface $entity, int $revision_id)

Loads an entity revision.

Parameters

EntityInterface $entity

The entity for which to load a revision.

int $revision_id

The revision ID to be loaded.

Return Value

EntityInterface|null

The revision or NULL if the revision does not exists.

Exceptions

PluginNotFoundException
InvalidPluginDefinitionException

static protected int|EntityInterface ensureVersionExists(int|EntityInterface $revision)

Helper method that ensures that a version exists.

Parameters

int|EntityInterface $revision

A revision ID, or NULL if one was not found.

Return Value

int|EntityInterface

A revision or revision ID, if one was found.

Exceptions

VersionNotFoundException