Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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.
Comment | File | Size | Author |
---|---|---|---|
#9 | 2952522-9.patch | 816 bytes | Wim Leers |
Comments
Comment #2
Wim LeersHow 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 tonew Relationship(…, $entity_list_metadata, …)
, this gets normalized in\Drupal\jsonapi\Normalizer\Value\RelationshipItemNormalizerValue::rasterizeValue()
and hence ends up being exposed.Comment #3
gabesulliceI 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
Comment #4
Wim LeersHeh :P
I think this needs feedback from @e0ipso.
AFAICT this is very much intentional…
Comment #5
e0ipsoHmm, 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.
Comment #6
e0ipsoComment #7
gabesulliceI think I originally misunderstood what this was.
Comment #8
BerdirThis 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)
Comment #9
Wim LeersNicely spotted, @Berdir! Crediting @Berdir for this change. Since @Berdir effectively created this patch, I'm directly RTBC'ing this.
Comment #10
larowlanCommitted 9eca7bb and pushed to 8.8.x. Thanks!