next-drupal icon indicating copy to clipboard operation
next-drupal copied to clipboard

Data from paragraph in paragraph not added in API return

Open GeneralBouLi opened this issue 3 years ago • 5 comments

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.

GeneralBouLi avatar Feb 01 '23 10:02 GeneralBouLi

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"])
  }

spiderneo avatar Feb 01 '23 12:02 spiderneo

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 ?

GeneralBouLi avatar Feb 01 '23 12:02 GeneralBouLi

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.

Screenshot from 2023-02-08 14-07-38

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.

Screenshot from 2023-02-08 14-08-43

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.

Screenshot from 2023-02-08 14-17-58 Screenshot from 2023-02-08 14-19-08 Screenshot from 2023-02-08 14-19-25

And this is the example Paragraph type (ParagraphFiles) template: Screenshot from 2023-02-08 14-22-12

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} />

p0zi avatar Feb 08 '23 13:02 p0zi

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.

GeneralBouLi avatar Apr 12 '23 12:04 GeneralBouLi

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.

GeneralBouLi avatar May 30 '23 09:05 GeneralBouLi