Postponed
Project:
Drupal core
Version:
main
Component:
jsonapi.module
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
15 May 2017 at 08:41 UTC
Updated:
14 Feb 2025 at 15:31 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
wim leersComment #3
wim leersSince the ability to do
$entity->toUrl('jsonapi')also requires aentity.$entity_type_id.jsonapiroute to exist, we'll need to take inspiration from #2293697: EntityResource POST routes all use the confusing default: use entity types' https://www.drupal.org/link-relations/create link template if available too.Comment #4
wim leersHere's a rough initial version.
Comment #5
wim leersThis is correct.
But this is not yet correct. Because a separate individual route is generated for each bundle of an entity type, this currently is using the last enumerated bundle and hardcoding that for all entities of this entity type.
For example, for
Nodeon a default install this will result in/jsonapi/node/page/<node ID>for all nodes, which is obviously wrong.IOW: this needs a different route definition.
Comment #6
wim leersNote that this is already resulting in
<link rel="jsonapi" href="/jsonapi/node/page/1" />automatically being added to the HTML<head>, as well as aLink:</jsonapi/node/page/1>; rel="jsonapi"response header!Comment #7
e0ipsoShouldn't it be UUID?
Comment #8
e0ipsoAre generating 4 different link types and embedding them in our responses:
We should be able to generate them all with link relation if we want to move in this direction, otherwise it will be inconsistent. Agree?
Comment #9
wim leers#7: no, that's the entity type ID, not the entity ID!
#8: Perhaps. What are the link relation names you suggest?
but…
jsonapi-relationshipandjsonapi-relatedlinks don't entirely make sense, because you'd need to add a URL for every related/relationship thing for that entity type + bundle! And that's something thatEntity::toUrl()simply does not support: it hardcodes the assumption that for every relationship there is only one URL.Therefore only
jsonapi-individualandjsonapi-collectionare ever possible. Which means that we might as well simplify it tojsonapiandjsonapi-collection.Comment #10
dawehnerI'm wondering whether it should be possible to pass along some of the parameters using the
$optionsparameter, if well, its optional.Comment #11
wim leers#10: I thought about that too, but that'd be violating the API, because:
Comment #12
wim leersI just stumbled upon the issue that aims to make it possible to have link relationships have multiple URLs: #2801067 — I left a comment there about this issue: #2801067-4: Link templates on entity types should support multiple links.
Comment #13
e0ipsoInteresting. Let's see how that evolves.
Comment #14
e0ipso@Wim Leers where do you think we stand on this after the past 4 months? I know that at some point you "gave up" because of implementation difficulties. Anything new in core land that can help us?
Comment #15
wim leersNo.
In #9, I wrote:
But the only link relationship that really matters is the individual JSON API resource. Because that is what allows the
/node/1HTML response to automatically have alink relationship in the response header, and from there, all other links can be followed. That's enough.
Updated patch attached, should be green.
Comment #17
wim leersI was working on integration test coverage. I didn't mean to add that to this patch.
This doesn't work yet, because #2878463: [PP-1] Define a JSON API link relation for entities is a hard blocker.
Comment #18
wim leersI think the link in #17 should have been #2282029: Automate link relationship headers for all entity types, not just nodes, but I'm not sure.
I don't see why we couldn't test against only
Nodefor now, then this wouldn't need to be blocked AFAICT.Comment #19
wim leersLet's get this going again.
jsonapilink template on non-internal entity types. Updatedjsonapi_entity_type_alter()accordingly.access contentpermission to be able to write an integration test.Link:</jsonapi/node/page/435>; rel="jsonapi", i.e. with the node ID rather than the node UUID.$url->access($this->currentUser)is called, which results in the route being constructed, but that fails because the provided parameter is the node ID, which\Drupal\jsonapi\ParamConverter\EntityUuidConverter::convert()doesn't know how to convert, nor does it want to. The problem, in other words, is the{node}route parameter that is firmly associated with the ID, not the UUID. We need something like{node:uuid}. That'd also solve the problem described in the previous bullet.I think we might need a routing system expert for this.
Comment #20
wim leersComment #21
dawehnerThere is a similar core issue for 4. isn't it? (#2353611: Make it possible to link to an entity by UUID). It wouldn't work in the current state, but we could check for something like node:uuid or so instead. I suggested a small change of direction for that issue, so we can maybe make more progress over there.
Comment #22
wim leersYep, I was contemplating linking to that issue, but didn't have the time to dig into the status/scope of #2353611, so thank you for doing that! ❤️
Comment #23
wim leersLet's make it clear that this is hard-blocked on #2353611. Posted #2353611-191: Make it possible to link to an entity by UUID to make that clear in the blocking issue too.
Comment #24
wim leers2.x will require >=8.5. Hence 1.x will never be able to do this.
Comment #25
wim leersComment #33
bbrala