Problem/Motivation

Revision support for individual entities will be provided in #2992833: Add a version negotiation to revisionable resource types. For entities that support revisioning, add revision links in serialized json api output for an individual entity for those revisions supported by the initial feature, rel:working-copy, rel:latest-version, and id:.

Proposed Solution

Add links to the links data structure for individual entities. These version links will only be included if the entity being returned supports revisions. The links to be included with use the revision id negotiation features in proposed in #2992833: Add a version negotiation to revisionable resource types, specifically the rel plugin negotiation:

GET /jsonapi/node/page/{uuid}?current_version=rel:working-copy
GET /jsonapi/node/page/{uuid}?current_version=rel:latest-version

Comments

justageek created an issue. See original summary.

wim leers’s picture

Category: Task » Feature request
Issue summary: View changes
Issue tags: +API-First Initiative
Related issues: +#2992833: Add a version negotiation to revisionable resource types
e0ipso’s picture

Status: Active » Needs review
StatusFileSize
new27.74 KB

Initial patch to add revision links. This patch depends on #2992833: Add a version negotiation to revisionable resource types. Added combined patch here.

e0ipso’s picture

Title: Provide links to entity revisions in json api output for individual entity » [PP-1] Provide links to entity revisions in json api output for individual entity

Status: Needs review » Needs work

The last submitted patch, 3: 2992836--revision-id-discovery--3.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

e0ipso’s picture

Stand-alone patch here.

e0ipso’s picture

Status: Needs work » Needs review
StatusFileSize
new922 bytes
new29.36 KB

Now that the plugin issue is back to green, let's get this re-tested.

Status: Needs review » Needs work

The last submitted patch, 7: 2992836--revision-id-discovery--7.patch, failed testing. View results

e0ipso’s picture

This patch will add links to the collections as well.

e0ipso’s picture

StatusFileSize
new596 bytes
new6.1 KB

There was a missing use statement.

wim leers’s picture

I'd also like to see working-copy-of, which should appear for non-default revision normalizations.

e0ipso’s picture

Status: Needs work » Needs review
StatusFileSize
new4.11 KB
new6.04 KB
new46.22 KB

This adapts the patch to the latest state of #2992833: Add a version negotiation to revisionable resource types.

Status: Needs review » Needs work

The last submitted patch, 12: 2992836--revision-links--12.patch, failed testing. View results

e0ipso’s picture

Title: [PP-1] Provide links to entity revisions in json api output for individual entity » [PP-1] Provide links to entity revisions in json api output
wim leers’s picture

Title: [PP-1] Provide links to entity revisions in json api output » Provide links to entity revisions in json api output

Now that #2992833: Add a version negotiation to revisionable resource types is RTBC, let's move this forward again! 💪

wim leers’s picture

Issue tags: +Workflow Initiative
e0ipso’s picture

Version: 8.x-1.x-dev » 8.x-2.x-dev
wim leers’s picture

gabesullice’s picture

wim leers’s picture

Title: Provide links to entity revisions in json api output » Provide links to entity revisions

Not opposed, but slightly concerned since that could take a while. But with 2.0 out, hopefully we can make significant progress there :)

wim leers’s picture

Title: Provide links to entity revisions » Provide links to resource versions (entity revisions)
wim leers’s picture

Title: Provide links to resource versions (entity revisions) » [PP-2] Provide links to resource versions (entity revisions)
Status: Needs work » Postponed
wim leers’s picture

Title: [PP-2] Provide links to resource versions (entity revisions) » [PP-1] Provide links to resource versions (entity revisions)
wim leers’s picture

Title: [PP-1] Provide links to resource versions (entity revisions) » Provide links to resource versions (entity revisions)
Status: Postponed » Active
Related issues: +#2995960: Add a Link and LinkCollection class to support RFC8288 web linking.
gabesullice’s picture

Title: Provide links to resource versions (entity revisions) » [PP-1] Provide links to resource versions (entity revisions)
Related issues: +#3015438: Wrap entity objects in a ResourceObject which carries a ResourceType

#2995960: Add a Link and LinkCollection class to support RFC8288 web linking. landed and added the LinkCollection class which I wanted to be used to add these links. However, it did not actually make use of LinkCollections on the resource object level. #3015438: Wrap entity objects in a ResourceObject which carries a ResourceType will accomplish that.

wim leers’s picture

Status: Active » Postponed
wim leers’s picture

Currently scrutinizing #3015438: Wrap entity objects in a ResourceObject which carries a ResourceType prior to commit. I wanted to be absolutely certain that this issue is indeed not only possible thanks to that other issue, but also significantly simpler in terms of code. I'm happy to report that this turns out to be true! In #12, we had to modify both the entity normalization and the top-level document normalization — even though both were for entities. Thanks to #3015438, we'll only have to make additions in one place. It also helps validate #2994193: [META] The Last Link: A Hypermedia Story :)

wim leers’s picture

Title: [PP-1] Provide links to resource versions (entity revisions) » Provide links to resource versions (entity revisions)
Status: Postponed » Needs review
StatusFileSize
new2.39 KB

Status: Needs review » Needs work

The last submitted patch, 28: 2992836-28.patch, failed testing. View results

gabesullice’s picture

SUPER pleased to see how simple this is now :D

Just a couple thoughts:

  1. +++ b/src/JsonApiResource/ResourceObject.php
    @@ -71,9 +73,17 @@ class ResourceObject implements CacheableDependencyInterface, ResourceIdentifier
    +      $self_url = Url::fromRoute(Routes::getRouteName($this->getResourceType(), 'individual'), ['entity' => $this->getId()]);
    

    I think the self links should be ?resourceVersion=rel:{vid} if the resource type is versionable.

  2. +++ b/src/JsonApiResource/ResourceObject.php
    @@ -71,9 +73,17 @@ class ResourceObject implements CacheableDependencyInterface, ResourceIdentifier
    +        $latest_version_url = $self_url->setOption('query', [JsonApiSpec::VERSION_QUERY_PARAMETER => 'rel:' . VersionByRel::LATEST_VERSION]);
    +        $this->links = $this->links->withLink(VersionByRel::LATEST_VERSION, new Link(new CacheableMetadata(), $latest_version_url, [VersionByRel::LATEST_VERSION]));
    +        $working_copy_url = $self_url->setOption('query', [JsonApiSpec::VERSION_QUERY_PARAMETER => 'rel:' . VersionByRel::WORKING_COPY]);
    +        $this->links = $this->links->withLink(VersionByRel::WORKING_COPY, new Link(new CacheableMetadata(), $working_copy_url, [VersionByRel::WORKING_COPY]));
    

    These should only appear if this particular version is not the latest version or working copy.

wim leers’s picture

Assigned: Unassigned » gabesullice

#30: be my guest to make that happen :) I'm glad the tests are catching the changes in JSON:API responses!

wim leers’s picture

Status: Needs work » Needs review
StatusFileSize
new3.07 KB
new3.05 KB
  1. ✅ But why by ID, and why not latest-version? I think because it allows the client to track server-side changes more easily, but I'd like us to document this explicitly.

Status: Needs review » Needs work

The last submitted patch, 32: 2992836-32.patch, failed testing. View results

gabesullice’s picture

#32:

1. Yes, and to easily disambiguate resource objects in #3009588: Provide a collection resource where a version history can be obtained (`version-history`, `predecessor-version` and `successor-version` link relations).
2. 😗👌


I'll push this over the finish line tomorrow.

gabesullice’s picture

Status: Needs work » Needs review
StatusFileSize
new17.54 KB
new15.46 KB
new20.03 KB
new10.4 KB

Okay, this should apply the appropriate expectations for resource object links (self, working-copy and latest-version).

In doing this I realized that we probably also need to update the self and related links under relationship objects. A relationship self link is essentially a URI for that relationship object. If a relationship differs between revisions, we don't want the relationship object on an individual response to be different from the result if the link is followed.

Let's add tests for those.


I don't want this next bit to block this issue because this issue has already sat for too long... but I do want to plant this seed now:

I didn't expect these links to be added within the ResourceObject class. I was hoping we would use this issue to pilot a more public API for LinkCollections (but keep it internal until we were satisfied with it).

I envisioned either a tagged service or plugin called a "link provider". It would be passed a LinkCollection object. In this issue, we would have implemented that service/plugin within the Revisions namespace (meaning all revision stuff was completely contained in that space). E.g.:

namespace Drupal\jsonapi\Revisions;

/**
 * @internal
 */
class RevisionsLinkProvider {

  public function alterLinks(LinkCollection $links) {
    $context = $links->getContext();
    if ($context instanceof ResourceObject && $context->getResourceType()->isVersionable()) {
      // add/update `self`, `latest-version` and/or `working-copy` links.
    }
    elseif ($context instanceof Relationship && $context->getRelationshipContext()->getResourceType()->isVersionable()) {
      //update `self` and `related` links. The `Relationship` ^ object does not exist yet.
    }
    return $links;
  }

}

The last submitted patch, 35: 2992836-35-should-fail.patch, failed testing. View results

The last submitted patch, 35: 2992836-35.patch, failed testing. View results

gabesullice’s picture

StatusFileSize
new3.59 KB
new23.41 KB
new20.91 KB

The last submitted patch, 38: 2992836-38-with-relationship-links.patch, failed testing. View results

gabesullice’s picture

Title: Provide links to resource versions (entity revisions) » [PP-1] Provide links to resource versions (entity revisions)
Related issues: +#3033473: Clean-up: Remove LinkManager
StatusFileSize
new11.35 KB
new30.09 KB
new63.84 KB

While I hate to make another prerequisite here, I think #3033473: Clean-up: Remove LinkManager is super close and will make this change a go a little smoother. It will also avoid having to reroll the change completely and will be more conceptually similar to what I showed in #35.

After we get this green, we can mark it Postponed, in the mean time, I'll keep them in sync as necessary.

Status: Needs review » Needs work

The last submitted patch, 40: 2992836-40-COMBINED.patch, failed testing. View results

gabesullice’s picture

Status: Needs work » Needs review
StatusFileSize
new791 bytes
new30.1 KB
new63.85 KB

Whoops, missed one variable rename.

Status: Needs review » Needs work

The last submitted patch, 42: 2992836-42-COMBINED.patch, failed testing. View results

gabesullice’s picture

Title: [PP-1] Provide links to resource versions (entity revisions) » Provide links to resource versions (entity revisions)
gabesullice’s picture

Assigned: gabesullice » Unassigned
Status: Needs work » Needs review
StatusFileSize
new4.44 KB
new34.55 KB

This should be green 🤞

wim leers’s picture

Status: Needs review » Reviewed & tested by the community

Looks 😍

  • gabesullice committed da85bb1 on 8.x-2.x
    Issue #2992836 by gabesullice, e0ipso, Wim Leers, justageek: Provide...
gabesullice’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.