When trying to nest paragraphs, the nested paragraphs won't be saved.

Motivation

Create a tabbed paragraphs type that uses paragraphs to sort its complex contents. Or create a named table with n rows, where this rows are a certain paragraph type.
The idea is like a mini node only existing in the listing of this paragraph.

How to reproduce

  • install drupal 8 beta12
  • install paragraphs and paragraphs_demo
  • in the paragraph type "text" add another field "nested_text" that is an reverence revisions type "Paragraph"
  • allow this nested_text to show only "text" or something else like "text+image"
  • create a Paragraphed article with "text" and add the "nested_text" field
  • hit save and see the nested text missing

Comments

janlaureys’s picture

+1 subscribed

Sidenote: Normal fields like images, text, etc. ARE saved inside the first paragraph reference field. Only the nested paragraph fields are being ignored/thrown away, nesting paragraph reference fields is not breaking the whole thing.

christian.wiedemann’s picture

+1 subscribed

duwid’s picture

+1 subscribed

miro_dietiker’s picture

Title: Nested Paragraphs wont be saved » Support nested paragraphs
Category: Bug report » Feature request

Bug or feature? ;-)
I'd say, this is more of a feature request to support nested paragraphs.

Paragraphs can be considered quite stable and we can release a 1.x version without this feature... And i'm not sure what complexity we need to resolve to support this request. It might be a big challenge or a simple fix finally...

Can someone provide a specific nice real life use case why this is needed?

luksak’s picture

I think this is a very important feature for paragraphs which I used a lot in 7.x.

The use case is the following: Paragraphs is most commonly used as a tool to provide flexible content management providing some kind of building blocks. Let's assume the is one named "Accordion". Nested inside the "Accordion" Paragraph we need to be able to add "Accordion items" having a title and a content field.

Since this feature existed in 7.x isn't this a requirement for a 1.x release to reach feature parity?

jeroen.b’s picture

Category: Feature request » Bug report

The 8.x version should contain all the features of 7.x version as stated on the project page, so this is indeed a bug.

luksak’s picture

Ok. What is the issue here? Any idea how we could solve this? If I know where to start, I'll try to fix this.

jeroen.b’s picture

I did not research yet, but it should be somewhere in src/Plugin/Field/FieldWidget/InlineParagraphsWidget.php.
Might be there is some array_parents issue somewhere.

jeroen.b’s picture

I have narrowed it down to the massageFormValues function.
The || !$form_state->isValidationComplete() prevents saving inside the embedded paragraph.

jeroen.b’s picture

StatusFileSize
new2.17 KB

I think I fixed it by extracting/validating the subform again after the validation of the full form.
For some reason the massageFormValues is only called on the top level elements after the validation has been completed.

I'm not sure if I fixed this in the right place, please check @miro_dietiker and @Berdir.

jeroen.b’s picture

Status: Active » Needs review
luksak’s picture

Works perfectly for me. Thank you!

miro_dietiker’s picture

Didn't check yet, but we especially also need to check the multilingual cases (currently broken due to a core change and paragraphs was needed to identify this core problem...) and write a test for this crazy stuff... ;-)

luksak’s picture

Status: Needs review » Needs work

I just lost nested paragraphs after reordering the parents. I added one at the bottom and dragged it to the top. After that the previously first paragraph lost it's children.

miro_dietiker’s picture

Issue tags: +Needs tests
jeroen.b’s picture

Status: Needs work » Needs review
StatusFileSize
new2.2 KB

Can you please try the attached patch? It should handle changing delta's correctly.

luksak’s picture

Looking good so far... I was unable to reproduce the bug with this patch.

LKS90’s picture

Seems to work with multilingual as well with this patch. Attached some screenshots. To make paragraphs work with multilingual setups again, #2543258: Entity references of untranslatable fields are not displayed in the correct translation needs to be reviewed/committed. Edit: Oh, and also entity_reference_revisions, I already have a patch for the current version of the core patch, but I'll wait until the core issue is fixed before opening the issue to update entity_reference_revisions #2551365: Fix missing parameter for viewElements and getEntitiesToView The issue, postponed since we wait for the core issue.

  • jeroen.b committed cc2f887 on 8.x-1.x
    Issue #2532756 by jeroen.b: Support nested paragraphs
    
jeroen.b’s picture

Status: Needs review » Fixed

Pushed to dev!

jeroen.b’s picture

Status: Fixed » Needs work

Oh wait, still needs tests...

LKS90’s picture

StatusFileSize
new5.14 KB

This test is only meant to show that nested paragraphs work, the way the test sets them up is rather ugly and not meant as an example on how to do it (I create the paragraph type, add fields for text and entity_reference_revisions and set up the form display). I tried to use $this->xpath('//p') to find the content, but the text itself is missing, might be useful though to count the existence of paragraphs (Check that the count is 4 in this test, for example).

miro_dietiker’s picture

I would recommend to test nested paragraphs with just unique text added to each paragraph and test it by example.

About setting up things: Doing so through the UI is pretty slow. The more common way is offer a dedicated test module that ships default config. Alternatively we could pack a nested paragraph setup into the demo and use the demo as a test setup as we do for some other tests. All we need would be a new nested paragraph type.

There is still that question pending about consistently deleting a node with its paragraphs. Did we take care of cascading deletes (or are we still not deleting the paragraphs at all?)

LKS90’s picture

Status: Needs work » Postponed

I have created an issue to add the 'Nested paragraphs' type to the paragraphs_demo module here: #2569483: Add nested paragraphs to paragraphs_demo. Writing a test should be way faster and easier then (basically just create a new paragraphed article, add some nested paragraphs and assertText the content, I think).

I'm not sure if the new issue is necessary, I could close this issue and add the tests with the new paragraph type, or add the paragraph type in this issue as well, I'm not sure. Feel free to decide for me :).

Edit: When I delete the node, the content is still in the database and the deleted field is not set to true.

miro_dietiker’s picture

The delete issue ended up at the entity_reference_revisions module and is not yet committed: #2429335: Deletion of referenced entities
I'm adding a statement about recursion there... ;-)

miro_dietiker’s picture

Status: Postponed » Closed (fixed)

This is not postponed, but successfully implemented in one of the referred issues above.