Data from paragraph in paragraph not added in API return
Hi,
We used next-drupal in front and back website for our new website. When we use field in a paragraph we can return field value in API but not when we use a paragraph in a paragraph.
I try to resolve this problem with API:JSON includes modules but it's worse because in API return links are removed and we don't have access to under paragraph data. I try https://www.drupal.org/files/issues/2022-01-14/3088239-21.patch patch too.
Do I miss a configuration ?
Thanks for your reply.
Did you configure correctly getParams function ?
For me i added .addInclude(["field_paragraph.field_other_paragraph"])
Example for my node page
if (name === "node--page") {
return params
.addInclude([
"field_image",
"field_paragraphe.field_image",
"field_paragraphe.field_paragraph_col",
"field_paragraphe.field_paragraph_col.field_image"
])
.addFields("node--page", [
"title",
"path",
"drupal_internal__nid",
"default_langcode",
"content_translations",
"field_image",
"field_paragraphe",
"field_colonne_droite",
"field_texte_entete",
"field_metas"
])
.addFilter("status", "1")
.addFields("media--image", ["field_media_image"])
.addFields("file--file", ["uri", "resourceIdObjMeta"])
}
Hi spiderneo,
I am a Drupal developer so I try to find solutions from Drupal not from front. Thanks for the example. When we have 2 paragraphs on forth possible can we add in .addInclude all paragraphs ?
Hello, I started implementing a solution for Drupal Paragraphs, it is untested implementation yet so i won't create a PR at the moment.
I recommend to decouple "addInclude" by creating separate function since Paragraphs structure from Drupal should be independent from place where they are attached to in Drupal side: block, page, article.

I think it is also a good practise to introduce Paragraph Container in Drupal that can hold nested Paragraphs, so we can asily traverse it recursively.

Another problem i try to fix is how to create flexible layout wrappers for nested Paragraphs within Paragraph Container, so when when we have mixed Paragraphs types in Paragraph Container.

And this is the example Paragraph type (ParagraphFiles) template:

And then we can invoke Paragraphs for a certain entity type:
<DrupalParagraphs entity={node.field_paragraph} node={node} />
<DrupalParagraphs entity={node.field_article_paragraph} node={node} />
Hi,
Thanks for your work and we will can test the paragraph solution next month. As I see it's really complicated to get values. I am a Drupal developper, as I can see, update the Drupal module to generate a full API with all values (job of Drupal) seems less complicated than add filters in Next package, particularly if paragraphs can be optionnals.
Thanks for the job you do and your reply.
Hi,
Our Drupal tech lead find a solution. JSON API Default is an extension we can use to do all requests with Drupal and remove not used data from API.
I hope it will help you too.