When requesting data via a related link, the type parameter and links are generated from the parent entity, not the entity type of the related item.
E.g. A request to /api/node/testlet_item/03615d8c-cba4-42ea-97c8-2b0309f9f3f7/field_item_instructions?_format=api_json should return items of type item_instruction--item_instruction, however the type is like so:
{
"data": [
{
"type": "node--testlet_item",
"id": "332b3d4f-dc64-4b27-ae0f-c410aea6a902",
"attributes": {
"id": "1",
"uuid": "332b3d4f-dc64-4b27-ae0f-c410aea6a902",
"langcode": "en",
"title": "This is just an example.",
"created": "1462476185",
"changed": "1462476185",
"default_langcode": "1",
"content_translation_source": null,
"content_translation_outdated": null,
"content_translation_status": null,
"content_translation_changed": null
},
"relationships": {
"type": {
"data": {
"type": "item_instruction_type--item_instruction_type",
"id": "2db5b75f-69e4-4fcb-865e-ba7dc66099f7"
},
"links": {
"self": "http://rema.dev/api/node/testlet_item/332b3d4f-dc64-4b27-ae0f-c410aea6a902/relationships/type?_format=api_json",
"related": "http://rema.dev/api/node/testlet_item/332b3d4f-dc64-4b27-ae0f-c410aea6a902/type?_format=api_json"
}
},
"uid": {
"data": {
"type": "user--user",
"id": "..."
},
"links": {
"self": "http://rema.dev/api/node/testlet_item/.../relationships/uid?_format=api_json",
"related": "http://rema.dev/api/node/testlet_item/.../uid?_format=api_json"
}
}
},
"links": {
"self": "http://rema.dev/api/node/testlet_item/...?_format=api_json"
}
}
],
"links": {
"self": "http://rema.dev/api/node/testlet_item/03615d8c-cba4-42ea-97c8-2b0309f9f3f7/field_item_instructions?q=es/api/node/testlet_item/03615d8c-cba4-42ea-97c8-2b0309f9f3f7/field_item_instructions&_format=api_json"
}
}
The issue is that the type is incorrectly listed as the type of the parent entity (node--testlet_item) and the links appear to be generated from that type as well.
Comments
Comment #2
e0ipsoAre you missing
... /relatedin the request url?Comment #3
gabesullicePerhaps... I've never fully understood that URL pattern, honestly. Regardless, I didn't hand write the request URL, instead I followed it from a link on the parent entity's document.
Comment #4
gabesulliceTo make the bug report a little more clear:
When visiting related resource link from a primary document, the related resource response should be a collection of the related resource objects.
The issue is that if one were to view
http://example.com/articles/1/author(example from the specification) the response would return the resource object for the author, however the type property would incorrectly be "article", not "author".Additionally, it appears that this is spilling into links on the related objects as well.
My intuition says that the CurrentContext service is probably blindly serving up the entity type of the parent, in turn causing the document normalizer to use the wrong entity type when serializing the type and links.
Comment #5
e0ipsoPlease, disregard the comment in #2, I wasn't thinking clearly at the time.
I see what you mean now. Are the id and the rest of the attributes in the payload correct?
Comment #6
e0ipsoOff topic, sorry about all the issue title changes. I'm following the best practise that commit messages should be read as: Once this is merged this will… {Insert your commit message here}.
Comment #7
gabesullice@e0ipso yes, the rest of the payload is correct. Also, that's a nice standard, I'll use that going forward.
Comment #8
e0ipsoComment #9
e0ipsoPatch and test. Merging if green.
Comment #12
e0ipsoFixes a tangential test.
Comment #13
e0ipsoThis issue uncovered a design flaw. We are setting the base resource config based on the route. One base route --> one base resource config.
This is fine with most implementations, but then Drupal. The issue is that a relationship can point to several resource types and therefore several resource configs. Since the relationships can become the base resource (via the related endpoint) we can have multiple resource config.
Comment #15
e0ipso