1

I'm looking to use the Paragraphs Drupal 8 module with a decoupled installation of Drupal 8 but would like the structure made in the admin area to be output in the JSON API responses.

How can I modify the JSON API responses from Drupal 8 to include this page structure data?

If anyone wants to know, having it decoupled & outputting structure information is a requirement I've been given.

2
  • 1
    Couple of things it would be useful to know - what do you define as "page structure data" in your installation, and what provides/links that structure to paragraphs?
    – Clive
    Commented Mar 7, 2019 at 13:40
  • @Clive So the idea is to create a page then use paragraphs to, for example, allow the user to add content for a "two column" paragraph layout and to a "two column" paragraph layout, or any other layout and reorder them. The order of these paragraph layouts would then be shown in the JSON API output so the front-end knows what layout is used and in what order. I hope that clears things up a little.
    – Neil Nand
    Commented Mar 7, 2019 at 14:38

1 Answer 1

1

It sounds like you want a compound document, the JSON:API mechanism that provides other referenced entities in a resource (e.g. a "page" content node that references other paragraphs). This is done via adding an include query parameter with a value that refers to a field's relational ID. An inclusion request will add an included array property with the related entity resource objects.

See the docs on Includes in the JSON:API docs for more concrete examples in action.

Since you mentioned it, ordering included resources isn't possible (IIRC); you might be able to infer order based on the Paragraph field. JSON:API is designed for minimal configuration and maximum adherence to the JSONAPI spec so you're limited to a couple of mechanisms to modify the output of the structured data.

1
  • You said "ordering included resources isn't possible". Currently the order in included is the actual order corresponding to the paragraph-field deltas, but now I am wondering if I can rely on it? This is not specific to paragraphs, but to all multi-value fields, I guess.
    – LarS
    Commented Mar 10, 2020 at 22:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.