Closed (fixed)
Project:
JSON:API
Version:
8.x-1.23
Component:
Documentation
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
29 Oct 2018 at 16:13 UTC
Updated:
13 Nov 2018 at 09:19 UTC
Jump to comment: Most recent
Comments
Comment #2
wim leersI'd recommend to not use this. There's a reason that we moved it out of
jsonapiand intojsonapi_extrasin #2982455: Add `jsonapi.entity.to_jsonapi` service.If you really want to use this, update to the latest JSON API Extras, the
jsonapi_extras.entity.to_jsonapiservice there has support for includes since #2995142: Support includes the EntityToJsonapi service.Comment #3
wim leersSorry, my answer was not complete enough. The answer to "Why?" can be found in #2982210: Move EntityToJsonApi service to JSON API Extras.
Comment #4
miiimoooThanks for the quick answer. Maybe I'm reading too much into your comments, but did you mean you wouldn't recommend to use jsonapi/extras to attach json in a preprocess/controller so it can be used in the theme or did you mean it's a bad idea at all? We're discussing this so would be great to get your input. Attaching drupalSettings seemed to like it could be fast and lightweight to provide initial data in a partially decoupled site. Maybe needs it's own issue. I'll try now with the JSON API extras.
Comment #5
wim leersYou're not reading too much into it — I personally believe that for consistency and maintainability reasons, the "entity to JSON API" service should ideally not exist at all. But you cite one of the few cases where it could be justified. In that case, it should IMHO be implemented as a subrequest, so that in the end, all the JSON API module does is provide responses to certain requests. I explained these concerns in #2874509: Provide service to simplify generating a JSON API representation of an entity in PHP code a long time ago.
This could indeed be a reasonable approach. For now, just use the
jsonapi_extras.entity.to_jsonapiservice. It's up to that service to be improved, you shouldn't have to worry about it :) Sorry for the distraction!