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

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

Etroid created an issue. See original summary.

etroid’s picture

StatusFileSize
new3.04 KB
ikeigenwijs’s picture

I have a client who goes overboard with the nesting, i 'll let you know how it goes.

nicoschi’s picture

Is this issue verified by someone else? I followed the exactly step to reproduce it on 8.x-1.13 without any patch but the paragraphs are cloned correctly.

anybody’s picture

We're running into the same problem at a customer project, I'll have a look. We're using layout_paragraphs, perhaps that's a different problem, let's see.

anybody’s picture

The patch was not enough for my layout_paragraphs issue, but indeed was required for my issue to work: #3218222: Cloning Entities with Layout Paragraphs (1.x) breaks structure and moves subparagraphs into Disabled Items

So I'll incorporate your patch there too and give an RTBC+1 here! We please need more feedback on cloning nested paragraphs.

vflirt’s picture

I do not see the need of this patch. Currently it is calling createDuplicate method of the entity and paragraphs do the same for nested paragraphs so you are just doubling the duplication. Everything seems to be working quite ok with 8.x-1.14.

anybody’s picture

@vflirt thank you for your feedback - I'll have a look at that in my other issue. I guess you're not using layout_paragraphs? For that 8.x-1.14 definitely isn't working.

vflirt’s picture

No, I am not using layout_paragraphs.

ikeigenwijs’s picture

we used the patch all year

smustgrave’s picture

Status: Active » Reviewed & tested by the community

Worked for me using just regular nested paragraphs

anybody’s picture

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

Thank you :)

anybody’s picture

StatusFileSize
new3.11 KB

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

It looks to me as if the patch is still needed for (nested) paragraphs cloning to work correctly.

marcusx’s picture

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.

seanb’s picture

heikkiy’s picture

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.

heikkiy’s picture

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.

bluegeek9 made their first commit to this issue’s fork.

guncha25’s picture

seanb’s picture

StatusFileSize
new3.37 KB

I had an issue cloning nested paragraphs with translations. Before we duplicate a paragraphs we must make sure we fetch it in the correct translation.

aelfendir’s picture

Thanks seanb! I tested your patch and it fixed the nested paragraphs + translations issue in my project.

scott_euser made their first commit to this issue’s fork.

scott_euser’s picture

Status: Reviewed & tested by the community » Needs review

Added test coverage, if someone can get this back to RTBC please so we can hopefully get this merged
Thanks!

csakiistvan’s picture

Environment

  • Drupal: 11.4.4
  • PHP: 8.5.5
  • Database: MariaDB 10.11.16
  • DDEV: v1.25.2
  • Quick Node Clone: 8.x-1.22
  • Paragraphs: 8.x-1.21
  • Entity Reference Revisions: 8.x-1.14
  • Browser: Chrome

Prerequisites

  • Enable quick_node_clone and paragraphs.
  • Create paragraph type QNC Child with a plain text field, and paragraph type QNC Parent with a plain text field plus an unlimited paragraph reference field limited to QNC Child.
  • Add an unlimited paragraph reference field to the Article content type limited to QNC Parent, and expose all three fields in the corresponding form displays.
  • Create an article with one parent paragraph containing one nested child paragraph. Note the paragraph IDs:
ddev drush sql:query "SELECT id, type, parent_id, parent_type FROM paragraphs_item_field_data ORDER BY id"
  • Remove Article from the editorial workflow if content moderation is enabled, so the clone form has no unrelated moderation state.

Steps

  1. Apply the fix from MR !1: make QuickNodeCloneEntityFormBuilder::cloneParagraphs() recursive and accept a ContentEntityInterface.
  2. Rebuild caches: ddev drush cr
  3. Go to /clone/<nid>/quick_clone and click Save.
  4. Open the original article and confirm the nested child paragraph is still shown.
  5. Re-run the paragraph query above and compare the parent_id of the original nested paragraph with the value noted in the prerequisites.
  6. Repeat steps 3–5 without the fix in place to compare the behaviour.
  7. Run the functional test added by the MR with and without the fix applied:
ddev exec bash -c 'SIMPLETEST_BASE_URL=http://web SIMPLETEST_DB=mysql://db:db@db/db \
  BROWSERTEST_OUTPUT_DIRECTORY=/var/www/html/web/sites/simpletest/browser_output \
  vendor/bin/phpunit -c web/core \
  web/modules/contrib/quick_node_clone/tests/src/Functional/QuickNodeCloneNestedParagraphsTest.php'

Expected results

  • Without the fix, the nested child paragraph should not be cloned: its parent_id should be repointed to the cloned parent paragraph and the original article should lose its nested paragraph.
  • With the fix, both the original and the clone should own an independent nested paragraph.
  • The functional test added by the MR should fail without the fix and pass with it.

Actual results

The bug could not be reproduced on 8.x-1.22 with plain nested paragraphs. Cloning through the UI produced an independent nested paragraph for the clone in both widget configurations (paragraphs and the legacy entity_reference_paragraphs), and the original nested paragraph kept its original parent_id. A code-level run of the unpatched cloneParagraphs() followed by a save gave the same outcome: the clone received a new nested paragraph and the original was untouched, because the current entity_reference_revisions / paragraphs versions already duplicate nested paragraphs recursively on save. This matches the earlier reports in comments #5 and #7 that the problem was not reproducible on 8.x-1.13 and 8.x-1.14, while the users who still saw it were using layout_paragraphs. The functional test added by the MR passes unchanged with and without the fix (1 test, 15 assertions), so it does not cover the reported defect. Applying the fix caused no regression: the module test suite shows the same 3 pre-existing failures before and after.

Remaining work

  • The test needs to fail without the fix — as written it does not demonstrate the bug.
  • The issue summary needs steps to reproduce that still fail on current paragraphs / entity_reference_revisions, most likely a layout_paragraphs structure or asymmetric translations rather than plain nesting.

Testing produced with the assistance of an LLM.