In #2843147-122, @xjm expressed concern about LinkManager being a "hopeful" deprecation. I share that concern. We've already deprecated it, so... let's follow through!

LinkManager was originally intended to serve as an extension point for module to provide HATEOAS links. However, we've never seen it used for this purpose in the wild.

Now, we have #2994193: [META] The Last Link: A Hypermedia Story, which is taking a much more serious and holistic approach to HATEOAS and is working toward a truly public API for hypermedia. We've even demonstrated the APIs it has added already in #3032468-7: Compatibility with upcoming JSON:API 2.2 release: JSON:API Extras 3.4!

Comments

gabesullice created an issue. See original summary.

gabesullice’s picture

StatusFileSize
new30.51 KB

Done.

gabriel.sullice jsonapi:rem $ git df 8.x-2.x --stat ./src
 src/Controller/EntityResource.php...
 src/LinkManager/LinkManager.php...
 src/Normalizer/EntityReferenceFieldNormalizer.php...
 3 files changed, 162 insertions(+), 287 deletions(-)

Stats from the src directory ^

gabesullice’s picture

Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, 2: 3033473-2.patch, failed testing. View results

wim leers’s picture

Status: Needs work » Needs review
StatusFileSize
new7.87 KB
new36.4 KB

This fixes most failures.

Status: Needs review » Needs work

The last submitted patch, 5: 3033473-5.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

wim leers’s picture

One fail. (And 5 CS violations.)

gabesullice’s picture

Status: Needs work » Needs review
StatusFileSize
new34.52 KB

Rerolled and fixed CS violations.

This should still fail.

Status: Needs review » Needs work

The last submitted patch, 8: 3033473-8.patch, failed testing. View results

gabesullice’s picture

Status: Needs work » Needs review
StatusFileSize
new833 bytes
new34.62 KB

This should pass 🤞

gabesullice’s picture

StatusFileSize
new2.7 KB

Patch for JSON:API Extras ^^^, all of which is test-only. Consumer Image Styles should be unaffected.

wim leers’s picture

#11: Only deletes for JSON:API Extras, yay! That means less brittleness, less coupling to (private) implementation details, less future breakage 👍

  1. 🎉 8 files changed, 172 insertions, 503 deletions.
  2. +++ b/src/Normalizer/EntityReferenceFieldNormalizer.php
    @@ -54,10 +39,13 @@ class EntityReferenceFieldNormalizer extends FieldNormalizer {
    -    assert($context['resource_object'] instanceof ResourceIdentifierInterface);
    ...
    +    assert($context['resource_object'] instanceof ResourceObject);
    

    🤔 Why are we changing this assertion? If I revert this change, tests still pass.

  3. +++ b/src/Normalizer/EntityReferenceFieldNormalizer.php
    @@ -54,10 +39,13 @@ class EntityReferenceFieldNormalizer extends FieldNormalizer {
    +    $links = array_map(function (Url $link) use ($link_cacheability) {
    +      $href = $link->setAbsolute()->toString(TRUE);
    +      $link_cacheability->addCacheableDependency($href);
    +      return ['href' => $href->getGeneratedUrl()];
    +    }, $this->getRelationshipLinks($context['resource_object'], $field->getName()));
    

    👍 Elegant!

  4. +++ b/tests/src/Functional/MessageTest.php
    @@ -26,6 +26,7 @@ class MessageTest extends ResourceTestBase {
    +
    

    🔍🐛 Accidental whitespace-only change, let's revert.

  5. +++ b/tests/src/Kernel/Normalizer/JsonApiDocumentTopLevelNormalizerTest.php
    @@ -279,8 +272,8 @@ class JsonApiDocumentTopLevelNormalizerTest extends JsonapiKernelTestBase {
    -        'self' => ['href' => 'dummy_entity_link'],
    -        'related' => ['href' => 'dummy_entity_link'],
    +        'self' => ['href' => Url::fromUri('internal:/jsonapi/node/article/' . $this->node->uuid() . '/relationships/uid')->setAbsolute()->toString(TRUE)->getGeneratedUrl()],
    +        'related' => ['href' => Url::fromUri('internal:/jsonapi/node/article/' . $this->node->uuid() . '/uid')->setAbsolute()->toString(TRUE)->getGeneratedUrl()],
    

    👌

  6. --- a/tests/src/Unit/LinkManager/LinkManagerTest.php
    +++ /dev/null
    

    ✅ This test coverage is hardly worth keeping, it's far more complex than the trivial code it provides test coverage for. Plus, our functional tests more than cover this.

    +++ /dev/null
    @@ -1,218 +0,0 @@
    -  public function testGetPagerLinks($offset, $size, $has_next_page, $total, $include_count, array $pages) {
    ...
    -  public function getPagerLinksProvider() {
    

    Only this test coverage is testing nontrivial code, but here too the test coverage is so tightly coupled to implementation details and burdened with such complex mocks that it is not at all clear how much reassurances this is actually getting us.

I'd fix point 4 on commit, but keeping NR for point 2.

gabesullice’s picture

StatusFileSize
new368 bytes
new34.26 KB

Fixed #12.4.

12.2: $context['resource_object'] gets passed to $this->getRelationshipLinks() which type hints ResourceObject. I was just updating the assertion to be "honest" about what was expected for the normalization context.

wim leers’s picture

which type hints ResourceObject

But that too doesn't use anything on ResourceObject, it only uses methods on ResourceIdentifierInterface. So why can't we just typehint to that?

gabesullice’s picture

Because a relationship is always present in the context of a resource object. Also, see: #2992836-40: Provide links to resource versions (entity revisions)

wim leers’s picture

Status: Needs review » Reviewed & tested by the community

That is a solid reason. I'm convinced :)

I'm RTBC'ing and committing because:

  1. this is requested by a core committer in #2843147-122: Add JSON:API to core as a stable module.4
  2. I am pretty confident @e0ipso agrees with this since he committed #3032468: Compatibility with upcoming JSON:API 2.2 release: JSON:API Extras 3.4 , which is also using the LinkCollection (the new intended API) infrastructure instead of LinkManager (the originally intended API)

  • Wim Leers committed bfc0358 on 8.x-2.x authored by gabesullice
    Issue #3033473 by gabesullice, Wim Leers: Clean-up: Remove LinkManager
    
wim leers’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

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