Nested paragraph support

Created on 18 November 2020, almost 4 years ago
Updated 16 January 2024, 9 months ago

Problem/Motivation

When cloning a node with paragraphs and nested paragraphs, the parent id of the original paragraphs of any level > 1 are inadvertently changed. This is because nested paragraphs are not being cloned correctly.

Steps to reproduce

Create content type "Article" with a paragraph field

Create paragraph type "Child" with one or more fields:
- heading (text)
- ...

Create paragraph type "Parent" with two fields:
- heading (text)
- paragraph entity reference

Now create a new article node with
- a parent paragraph with some content
- a nested child paragraph with some content

Clone the node and check the DB:
- Assert the nested child paragraph was not cloned, but has its parent id updated instead.

Proposed resolution

The \Drupal\quick_node_clone\Entity\QuickNodeCloneEntityFormBuilder::cloneParagraphs should be recursive and apply the logic to all nested paragraphs as well.

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

RTBC

Version

1.0

Component

Code

Created by

🇺🇸United States Etroid

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇩🇪Germany Anybody Porta Westfalica

    @Maintainer: Any plan to merge this after 11 months?
    Would be great to finish this. We're also working on finishing 🐛 Cloning Entities with Layout Paragraphs breaks structure and moves subparagraphs into Disabled Items RTBC

    Thank you :)

  • 🇩🇪Germany Anybody Porta Westfalica

    Here's the static patch from MR!1 as of now!

  • 🇩🇪Germany marcusx

    I tried to reproduce this as I have several nested paragraphs and thought I would need this patch. But at the moment I cannot produce any cloning issues with those nested paragraphs.

    For me, everything is fine without the patch.

  • 🇳🇱Netherlands seanB Netherlands

    Linking 🐛 It is not possible to react to an entity being duplicated Needs work and Paragraph Library supports Entity Clone module Needs work since that would allow the paragraphs module to take care of the clones generically when an entity is duplicated.

  • 🇫🇮Finland heikkiy Oulu

    We are experiencing a similar issue.

    We have a client who is creating templates for complicate pages with nested paragraphs. They have for example accordion type paragraphs which contain multiple levels of paragraphs.

    We were investigating an issue where it seems like editing two different clones makes the content from the other clone disappear until the content is saved again. I presume that the parent paragraph id is always the same and it gets mixed up between the contents.

    We will test if this patch will solve the issue for us.

  • 🇫🇮Finland heikkiy Oulu

    A small update. I tried today to reproduce the issue in my local but so far I have not been able to. I would like to ask for help from others here to help me understand that what database tables might be affected if a nested paragraph is cloned and the parent paragraph id is not duplicated correctly?

    I did however update both Paragraphs and Quick node clone to latest version which might also affect my testing. I will also try with the older version.

    I will also try to explain our structure a bit more to understand the situation.

    We have some event content types where there is a nested paragraph like this:
    - Section
    -- Accordion
    --- Accordion item
    --- Accordion item
    - Section
    -- Accordion
    --- Accordion item
    --- Accordion item

    What happens is that there are several contents which are cloned from the same template. And randomly it happens so that the content first looks fine but then suddently the Section and Accordion paragraphs seem to be intact but the Accordion items are missing. And resaving the clone brings them back.

    Also notable is that we are using Asymmetric translations widget module to bring better support for different language versions.

Production build 0.71.5 2024