Problem/Motivation
It's difficult to determine the Entity for a Menu Item, or the Menu Item for an entity.
Steps to reproduce
1. Install Drupal and JSON:API Menu Items module
2. Create Node with Menu link
3. Visit `/jsonapi/menu_items/{{menu_name}}` or `/jsonapi/node/{{type}}/{{uuid}}` and try to find link between items.
Proposed resolution
1. Use the JSON:API Hypermedia to make a link between the resources.
2. Create computed relationships between the resources.
Link types:
- menu_item: Node/Entity -> Menu Link Content
- related: Menu Link Content/JSON:API Menu Item -> Node/Entity
- menu_subtree: Node/Entity -> JSON:API Menu Items filtered by menu_item as parent
- menu_siblings: Node/Entity -> JSON:API Menu items filtered by menu_item parent as parent
Remaining tasks
1. Proof of concept approaches
2. Make a decision on correct way to move forward
3. Write code, tests and documentation
User interface changes
N/A
API changes
Unknown
Data model changes
N/A
Release notes snippet
Original report by kentr
I have a menu which contains links to nodes.
I want to get the JSON:API URLS for the nodes that the menu contains.
I don't see a path in the data to connect the dots.
Example
Here's the JSON for the menu item.
Edit: Removed.
That's a page content type.
The direct URL for the resource is https://example.com/jsonapi/node/page/70f51f4b1-a7d4-4f7d-9530-489a5e6db...
How can I determine the direct URL for the node from the menu item response?
Issue fork jsonapi_menu_items-3198306
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
kentr commentedComment #3
decipheredI personally use the Decoupled Router module to turn the
link.uriinto the JSON:API Resource data.Comment #4
decipheredHowever, I think this should become a feature request, because there's no reason that the Decoupled Router should be required.
Instead, links via the JSON:API Hypermedia module should be added to any related resources:
- Node for a Node link
- View / JSON:API Views for a View link
- etc
Comment #5
decipheredComment #6
decipheredComment #7
realityloop commentedIs there any reason not to add relationships on a given menu entries json data, seems like a lot of queries in frontend could be drastically reduced if each menu entry contained a relationships for:
let the discussion commence..
Comment #8
decipheredGiven that the data can be easily filtered out using the
?fieldsfilter, I don't see that it should be an issue.Comment #9
larowlanWhat does the json api spec say for stuff like this?
Comment #10
decipheredhttps://jsonapi.org/format/#document-resource-object-relationships
The most relevant statement I could see was this one:
I couldn't find a clear separation of what should be considered a relationship and what should be considered a related resource link though.
Comment #12
realityloop commentedSeems this has been merged without being marked so here?
Comment #13
decipheredNo, it does not appear that this has been merged, but the patch no longer appears to apply.
Need re-roll.
Comment #14
decipheredI've rebased the feature branch against 1.2.x and all seems well.
I don't believe this feature is entirely finished, and could definitely do with some automated tests regardless, so leaving this @ Needs work for the moment.
Comment #15
othermachines commentedI'm setting up a decoupled Gatsby/Drupal site...Never mind, I went another route. :)Comment #17
sanjay.maharjan commentedHi @Deciphered ,
I have added a small change to your MR ( added accessCheck() on getQuery() method ) to make it compatible with D10.
Thank you
Sanjay