Cloning nested paragraph creates shared child reference

Created on 4 March 2025, about 1 month ago

Problem/Motivation

On a new node creation, when cloning a paragraph containing nested paragraph child(s), the original and cloned paragraphs point to the same child entity after the node save.

Steps to reproduce

1. Go to https://simplytest.me
2. Launch a site using Paragraphs 8.x-1.x-dev
3. Create 2 new paragraph types, a) Text containing a text field and b) Section containing a paragraph reference field of Text
4. Update the Basic page content type to contain a Content field that's a paragraph reference field of Section
5. Add a new Basic page
6. Add some text to the first Section > Text, e.g. "Hello World"
7. Now click on the "..." of the Section and click "Duplicate"
8. Update the text of cloned Section > Text to something else, e.g. "Hello World2"
9. Save the node
10. Both text will display "Hello World2"

Proposed resolution

In this issue: https://www.drupal.org/project/paragraphs/issues/3495373 📌 Support duplicate hook Active
A new condition !$item->entity->isNew() was introduced to prevent nested paragraphs from being cloned in this scenario. However, I'm uncertain about the original intent behind this change, so I can't suggest a solution at this stage.

🐛 Bug report
Status

Active

Version

1.19

Component

Code

Created by

🇹🇼Taiwan peterwcm

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

Merge Requests

Comments & Activities

  • Issue created by @peterwcm
  • Pipeline finished with Success
    about 1 month ago
    Total: 352s
    #440640
  • 🇮🇳India arunsahijpal

    Hi @peterwcm,
    I've updated the createDuplicate method please check.

    Also @berdir pls check is this a good solution?

    Thanks,
    Arun

  • 🇹🇼Taiwan peterwcm

    Hi @arunsahijpal,

    Thanks for working on this. The patch fixes the issue, but it causes orphaned paragraphs to be created before users save the node. I think there could be issues with translations as well.

    I'm puzzled about the !$item->entity->isNew() condition, as it seemed to work fine without it before. Could we consider removing that condition instead? @berdir

    Regards

    Peter

  • Pipeline finished with Failed
    about 1 month ago
    Total: 639s
    #441719
  • 🇮🇳India arunsahijpal

    @peterwcm,

    I've updated the code and now no more orphaned paragraphs and everything saves when the node saves by referencing the entity directly instead of manually setting target_id.
    and I also think this condition !$item->entity->isNew() is not necessary.
    For the translation thing there is one limitation that - Paragraphs are referenced entities, not simple text fields.
    Drupal does not natively support translating entity reference fields.
    When I tried to translate it shows this error

    * (unsupported) Paragraphs fields do not support translation
    

    . Yo can checkout this link for more info .

    I think there is one tot check translation with Paragraphs Library module but I'm not sure.
    Could you pls check it, if it works then I think we can safely remove that condition.

  • 🇹🇼Taiwan peterwcm

    Hi @arunsahijpal,

    Thanks for addressing this so quickly.
    I just did some quick tests, and the latest patch has fixed the issues.

Production build 0.71.5 2024