Add feature to clone entities by reference fields like Paragraphs

Created on 1 June 2023, over 1 year ago
Updated 15 April 2024, 7 months ago

Problem/Motivation

Will be good to have a feature to clone entities by reference fields. For example, a node has an entity reference field with paragraphs, and when creating a clone of this entity - the related paragraphs should also be cloned.

Steps to reproduce

1. Get a node with several paragraphs.
2. Clone this node via Content Entity Clone.
3. Make an edit in a paragraph content on the cloned node.
4. See that those changes are applied to the source node too, but shouldn't, from the content editor's logic perspective.

Proposed resolution

Add an option "Clone related entities" to the reference fields.

Remaining tasks

User interface changes

API changes

Data model changes

✨ Feature request
Status

Needs work

Version

1.0

Component

Code

Created by

πŸ‡¦πŸ‡²Armenia murz Yerevan, Armenia

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

Comments & Activities

  • Issue created by @murz
  • πŸ‡¦πŸ‡²Armenia murz Yerevan, Armenia
  • πŸ‡¬πŸ‡§United Kingdom SirClickALot Somerset

    Agreed, but strictly only with an option in my opinion because often, we might others to clone our nodes that contain references to Paragraphs they they should not own copies of.

    For example, in our educational site we have Chapters of learning.
    Chapters of learning are broken up into Topics.
    Topics are rigorously-vetted content reviewed by senior education specialists.

    A Teacher might wish to make a copy of a Programme and make a variation of their own and that's fine but if they choose to keep one or more Topics then there is no way that they should have ownership of that content because we cannot then vouch for its quality.

    While I can see your requirement here, I also think it's beyond the scope of what this module aims to achieve which is merely to pre-fill a form with existing values, with the emphasis on the word values.

    By contrast, you may find that the Replicate UI β†’ module is what you are after because that one does exactly what you're asking for here and does so however deep the tree is.

  • πŸ‡¦πŸ‡²Armenia murz Yerevan, Armenia

    I agree that this should be optional and disabled by default.

    But still, it is the case for the current module because other solutions like the suggested "Replicate UI" or "Entity Clone" - immediately create a copy, instead of pre-filling the entity form.

    Seems, we still can pre-fill reference fields there too, if the form uses the "Inline Entity Form" widget type, to implement this feature.

    Because with that "Paragraphs" module, we can fill manually the node form, add several paragraphs there, and they will be stored in the form state, without creating actual entities until we click "Create" and submit the full form.

    Can we implement the same behavior by pre-filling referenced fields?

  • πŸ‡¦πŸ‡²Armenia murz Yerevan, Armenia

    And from the implementation point of view, seems we can create a new plugin, like the current "EntityLabelCloneSuffix", attached to only the "entity_reference" field type, that will do the thing.

  • πŸ‡ΊπŸ‡¦Ukraine Tolyan4ik Lviv

    Here is patch with Field processor to duplicate related entity.

  • @tolyan4ik opened merge request.
  • Status changed to Needs review over 1 year ago
  • πŸ‡ΊπŸ‡¦Ukraine Tolyan4ik Lviv
  • Status changed to RTBC over 1 year ago
  • πŸ‡¦πŸ‡²Armenia murz Yerevan, Armenia

    I've tested the proposed fix and it works pretty stable! A couple of renamings and minor fixes from my side have been pushed, so let's move to Reviewed status.

  • πŸ‡΅πŸ‡±Poland dmitry.korhov Poland, Warsaw
  • Status changed to Needs work 7 months ago
  • πŸ‡―πŸ‡΅Japan orakili

    This doesn't seem to work with some entity reference widgets like the media library or the inline entity form β†’ module.

    @Murz, would you be able to indicate with what widgets this plugin worked?

Production build 0.71.5 2024