Closed (works as designed)
Project:
JSON:API
Version:
8.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
2 Nov 2017 at 07:17 UTC
Updated:
6 Nov 2017 at 13:16 UTC
Jump to comment: Most recent
Comments
Comment #2
wim leersIt's not yet clear to me what the use case is.
I have two high-level remarks:
KernelEvents::RESPONSEsubscriber?Comment #3
e0ipsoI would use the response event as well for that.
Comment #4
ndavison commentedSo the idea would be similar to
hook_ENTITY_view- acting on entities before they are sent to the "rendering" engine. In the case of JSON API, probably as late as possible before the JSON encoding happens. Currently I can't see a way to hook into when an entity is about to be rendered by JSON API (entity load is a bit too wide a net).This may be possible using
KernelEvents::RESPONSE, but I suspect getting the entities being rendered from there will lead to repeating JSON API's route -> entities logic. I'd be very happy though if this is not the case.It's easy for me to say as a non maintainer of the module, but would adding a few events passing in entities before encoding be a significant support burden going forward? I can't imagine the API changing much (provided
EntityInterfaceis here to stay in D8).Comment #5
e0ipsoRemember that the module does not render anything. The closest to
hook_ENTITY_viewis to add your own entity normalizer with a higher priority and extend from the one provided in the module.Comment #6
ndavison commentedThanks for that suggestion I hadn't considered taking an approach like that. It will probably be very close to what I need to achieve.
Comment #7
wim leersIndeed.
Also don't forget about https://www.drupal.org/project/jsonapi_extras, which provides a UI for commonly desired customizations!
Comment #8
wim leers