Discovered as part of #2945093: Comprehensive JSON API integration test coverage phase 3: test JSON API-specific use cases: related/relationship routes, includes and sparse field sets.

File relationship resource identifiers get an added meta member like:

[
  'id' => $thumbnail->uuid(),
  'type' => 'file--file',
  'meta' => [
    'alt' => 'Thumbnail',
    'width' => '180',
    'height' => '180',
    'title' => 'Llama',
  ],
];

Should this be removed as part of #2929932: Work around core's ill-designed @FieldType-level TimestampItemNormalizer normalization until #2926508 lands? No. See #2.

This would be a breaking change, so it would need to be added to #2952293: Branch next major: version 2, requiring Drupal core >=8.5.

CommentFileSizeAuthor
#9 2952522-9.patch816 bytesWim Leers
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

gabesullice created an issue. See original summary.

Wim Leers’s picture

How is this related to #2929932: Work around core's ill-designed @FieldType-level TimestampItemNormalizer normalization until #2926508 lands?

AFAICT the problem is that \Drupal\jsonapi\Normalizer\EntityReferenceFieldNormalizer::normalize() collects entity metadata (see $entity_list_metadata), passes that to new Relationship(…, $entity_list_metadata, …), this gets normalized in \Drupal\jsonapi\Normalizer\Value\RelationshipItemNormalizerValue::rasterizeValue() and hence ends up being exposed.

gabesullice’s picture

How is this related to #2929932: Work around core's ill-designed @FieldType-level TimestampItemNormalizer normalization until #2926508 lands?

I didn't look into this at all. They seemed similar because they're both related to file normalization. Since you've looked at this and are familiar w/ the other issue and don't see a connection, we can consider the question answered (the answer seems to be "no") :P

Wim Leers’s picture

Assigned: Unassigned » e0ipso

Heh :P

I think this needs feedback from @e0ipso.

AFAICT this is very much intentional…

e0ipso’s picture

Hmm, what's the motivation to remove this? JSON API's relational approach is a pure link. A relationship cannot be contextualized because it's only a type and an ID. In other words, the relationship itself cannot have extra attributes. In Drupal we can have extra attributes (see the example in the IS). This data does not belong to the image, nor to the article, it belongs to the relationship.

Adding the information to the meta is the only way to stay compliant and be able to access this information from the consumer.

e0ipso’s picture

Assigned: e0ipso » Unassigned
gabesullice’s picture

Status: Needs review » Closed (works as designed)

I think I originally misunderstood what this was.

Berdir’s picture

Status: Closed (works as designed) » Active

This issue is still referenced in \Drupal\Tests\jsonapi\Functional\MediaTest::getExpectedGetRelationshipDocumentData, should we use this to remove that todo? (would need to move to core for that)

Wim Leers’s picture

Title: Remove `meta` from file--file resource identifiers » Remove @todo that is no longer relevant
Project: JSON:API » Drupal core
Version: 8.x-1.x-dev » 8.8.x-dev
Component: Code » jsonapi.module
Category: Plan » Task
Priority: Normal » Minor
Status: Active » Reviewed & tested by the community
Issue tags: +API-First Initiative
FileSize
816 bytes

Nicely spotted, @Berdir! Crediting @Berdir for this change. Since @Berdir effectively created this patch, I'm directly RTBC'ing this.

larowlan’s picture

Status: Reviewed & tested by the community » Fixed

Committed 9eca7bb and pushed to 8.8.x. Thanks!

  • larowlan committed 9eca7bb on 8.8.x
    Issue #2952522 by Wim Leers, gabesullice, e0ipso, Berdir: Remove @todo...

Status: Fixed » Closed (fixed)

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