Could this module be used to duplicate/clone paragraphs inside the same node?

I need to fill a lot of paragraphs which only vary in some details. So cloning a just filled paragraph would be great help for users.

Comments

geraldito created an issue. See original summary.

geek-merlin’s picture

Status: Active » Closed (works as designed)

Hmm, if the node is already saved, this should be just normal operations of the module.
If you want to clone paragraphs inside the form (so they are not yet saved anywhere) this sounds like a totally different module.

Can this help you?

geraldito’s picture

Thanks for your answer. My issue is more about creating clones of paragraphs in new (and not already saved) nodes. So you say that your module is not appropriate for doing that. Perhaps I should look for a Javascript solution as data has to be copied from fields inside the add node form.

geek-merlin’s picture

Do you need "add empty" as well as "clone"? Do you need to copy different items or always the same?

If the use case is "always clone the first one" then you may intercept the "add" process.

geraldito’s picture

Ideally I would have a "add empty" and additionally a "clone" button. But I could live with "always clone the first/last one".

So you propose to intercept the "add" process by hook_form_alter or by hook_preprocess_paragraph? Thanks again for your help.

geek-merlin’s picture

> So you propose to intercept the "add" process by hook_form_alter or by hook_preprocess_paragraph? Thanks again for your help.

I can't remember what we have there, and my gut feeling is to go deeper than form alter, so hook_preprocess_paragraph might be a good candidate. For the experienced it might even be possible to decorate the paragraphs object (if you want to do that and invest some learning, look up "decorator pattern").

geraldito’s picture

I just found out that the Paragraphs Experimental Widget shows by default a "Duplicate" button which actually does what I'm looking for: Cloning the content of all paragraph fields into a new paragraph. Thanks for your help!