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
| Comment | File | Size | Author |
|---|
Issue fork quick_node_clone-3183249
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
Comment #3
etroid commentedComment #4
ikeigenwijs commentedI have a client who goes overboard with the nesting, i 'll let you know how it goes.
Comment #5
nicoschi commentedIs 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.
Comment #6
anybodyWe'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.
Comment #7
anybodyThe 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.
Comment #8
vflirt commentedI 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.
Comment #9
anybody@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.
Comment #10
vflirt commentedNo, I am not using layout_paragraphs.
Comment #11
ikeigenwijs commentedwe used the patch all year
Comment #12
smustgrave commentedWorked for me using just regular nested paragraphs
Comment #13
anybody@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 :)
Comment #14
anybodyHere'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.
Comment #15
marcusx commentedI 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.
Comment #16
seanbLinking #3040556: It is not possible to react to an entity being duplicated and #3211482: Paragraph Library supports Entity Clone module since that would allow the paragraphs module to take care of the clones generically when an entity is duplicated.
Comment #17
heikkiy commentedWe 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.
Comment #18
heikkiy commentedA 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.
Comment #20
guncha25 commentedComment #21
seanbI had an issue cloning nested paragraphs with translations. Before we duplicate a paragraphs we must make sure we fetch it in the correct translation.
Comment #22
aelfendir commentedThanks seanb! I tested your patch and it fixed the nested paragraphs + translations issue in my project.
Comment #24
scott_euser commentedAdded test coverage, if someone can get this back to RTBC please so we can hopefully get this merged
Thanks!
Comment #25
csakiistvanEnvironment
Prerequisites
quick_node_cloneandparagraphs.editorialworkflow if content moderation is enabled, so the clone form has no unrelated moderation state.Steps
QuickNodeCloneEntityFormBuilder::cloneParagraphs()recursive and accept aContentEntityInterface.ddev drush cr/clone/<nid>/quick_cloneand click Save.parent_idof the original nested paragraph with the value noted in the prerequisites.Expected results
parent_idshould be repointed to the cloned parent paragraph and the original article should lose its nested paragraph.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 (
paragraphsand the legacyentity_reference_paragraphs), and the original nested paragraph kept its originalparent_id. A code-level run of the unpatchedcloneParagraphs()followed by a save gave the same outcome: the clone received a new nested paragraph and the original was untouched, because the currententity_reference_revisions/paragraphsversions 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 usinglayout_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
paragraphs/entity_reference_revisions, most likely alayout_paragraphsstructure or asymmetric translations rather than plain nesting.Testing produced with the assistance of an LLM.