Problem/Motivation

I find the duplicate option in the experimental paragraph widget to be a big plus, allowing me to rapidly build out a page before going on to edit the duplicates.

Most page builder systems have such functionality, usually represented by a small icon in the UI.

A similar pattern would fit very nicely next to the existing edit and delete icons.

Visual of UI with a duplicate icon

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

CommentFileSizeAuthor
layout_paragraphs_duplicate.png116.15 KBmrpauldriver
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

MrPaulDriver created an issue. See original summary.

mrpauldriver’s picture

Issue summary: View changes
mrpauldriver’s picture

Issue summary: View changes
mrpauldriver’s picture

Title: Option to duplicate a parapgraph » Option to duplicate a paragraph
emont88’s picture

I would love this feature too. Not sure if I can offer much on the coding side but I'm certainly willing to help test.

justin2pin’s picture

Thanks for this - I bet this feature would benefit a number of users out there. I wonder if we could implement this kind of thing as a separate module, though, that extends LP. Perhaps a simple form_alter to add the duplicate button, with the necessary submit hooks to make it happen?

I'd be happy to review a patch or answer any questions about the API that took this in that direction.

mrpauldriver’s picture

It needs to be in there Justin. Not a submodule, just baked in. If just a form alter then fairly straightforward?

Sorry but I'm not a coder, so can't I provide a patch, but I'm most definitely a 'Road to Damascus' convert to Layout Paragraphs.

Brilliant module which takes Drupal forward a long way. I'm sure others will agree.

mrpauldriver’s picture

The main question in my mind is whether this feature request should apply only to paragraphs, and not to layout paragraphs?

I suspect that layout paragraphs and all the recursive nonsense that would follow might be a step too far.

johnpitcairn’s picture

How about if, instead of it being next to edit/delete, the add paragraph (+) popup included a duplicate this [paragraph type] option? That would allow the user to duplicate above or below in one step.

alemadlei’s picture

@justin2pin if you provide me some quick guidelines about which files to update or what to modify and what to set, I could try coding this, as this is a feature recently requested to me.

johnpitcairn’s picture

Now that there is a 2.x branch that is a major refactor, I think we need a roadmap for what is still in-scope that could be committed as a patch to 1.x, vs a new feature that needs to be developed against 2.x. This has proved to be a major problem for other modules and I'd hate to see it perpetuate here. @justin2pin, where should our effort be focused?

justin2pin’s picture

Status: Active » Needs work

I agree this would be a great feature to add to Layout Paragraphs... great seeing the work on this so far!

At this time, we are focussing entirely on the 2.0.x branch for new development. We expect all current features to be included in 2.0.x, and there will be a simple upgrade path (when ready, you'll just switch to the new version). The code is changing, but the data storage is staying the same.

We will also address major bugs for 1.0.x to make sure this module continues to work well for everyone as is.

All that said, I'm happy to review and commit RTBC issues for 1.0.x.

anybody’s picture

Version: 1.0.x-dev » 2.0.x-dev

Let's switch this to 2.x! Really helpful and interesting feature, which could in large parts perhaps be reused from Paragraphs core or other paragraphs modules. Also it might in parts be related to the whole entity cloning topic #3218226: Cloning Entities containing Layout Paragraphs breaks structure?

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

justin2pin’s picture

@Anybody - agreed this is better tagged 2x, but I don't think we should build this directly into LP. I'd rather either (a) create a submodule, or (b) just create a separate standalone module for handling this. The 2x branch provides APIs that should make this kind of thing pretty simple.

anybody’s picture

@justin2pin, you're the maintainer, you decide :) My 2 cent is that it makes sense in the module itself. Directly or as submodule. It's a very typical feature, I guess, used by many inexperienced content editors / site admins. At least that is what we see in Wordpress Gutenberg / Elementor every day...

I'd even vote for direct inclusion, but as said above, you're the maintainer :)
I really appreciate your work and your commitment a lot! GREAT module!

justin2pin’s picture

Hah thanks - will consider and keep this open in the meantime.

hudri’s picture

I'm with @Anybody in this matter, I'd vote for adding this into the main module. Paragraphs itself also has the duplicate option in the main widget. Given the nature of Paragraphs vs. core layout builder, where every node starts completely empty, duplication is a very common operation.

I've added a public duplicateComponent() in LayoutParagraphsLayout. The field widget is using this via a dedicate DuplicateController now, and Replicate could re-use this, because it has support from Paragraphs itself, triggering an event there. Quick Node Clone or Entity Clone are still out of luck.

I've tried to keep this as simple as possible, no extra permissions, no placement logic, quite the same behavior as original Paragraphs itself.

If somebody has experience writing proper tests, I would appreciate any help. I'm quite in-experienced writing tests and getting it all done inside the Drupal infrastructure.

hudri’s picture

Status: Needs work » Needs review
mrpauldriver’s picture

Drupal does not have a killer app when it comes to page builder systems and inferior CMS platforms are way ahead in this respect.

Layout paragraphs could change this, so much better if this feature was baked in.

If easier to manage as a sub module then fair enough, but most certainly not as more contrib.

justin2pin’s picture

@hudri - Awesome work, thanks for this! Just pulled from your issue fork and it works perfectly. I'm going to commit a few suggested changes... let me know what you think. Also the icon is great too.

I agree this feature is important, but I still think we need to be able to turn it on/off. A few ways of doing that:

  • Make it a sub-module (more code/overhead than might be necessary)
  • Add a permission for enabling the feature (would require enabling the layout paragraphs permissions submodule, then configuring permissions)
  • Add a site-wide setting
  • Add a setting to the field widget and formatter

Thoughts?

justin2pin’s picture

@hudri - My commits include rebasing the latest 2.0.x -- apologies for the messy diff. Comments / changes / feedback welcome.

Thanks again for the work on this -- let's figure out the best way to make this something admins can turn on / off.

johnpitcairn’s picture

A submodule or contrib for this feels like kicking the can down the road. It's core functionality, ask any editor.

What is the use case for restricting duplication by role? How might it be abused so per role permissions would help?

Per widget instance is intriguing, but I can't think of a use case for site builders where you'd want to restrict duplication based on the parent entity/field.

Per formatter instance I think would be just weird. Why?

I can however see a use case for it being a 3rd party setting on paragraph types, where duplication in the same parent could result in confusing outcomes for site visitors or hard decisions for editors.

anybody’s picture

Add a setting to the field widget and formatter

is the only option that makes sense for me, as I'm with @John Potcairn, if you want a general setting for that. If not, use a separate permission in the layout paragraphs permissions submodule.
But I think it's not required.

What's needed is to ensure that only paragraphs (types) can be cloned, which the user is allowed to create from scratch. Because in the end it's a shortcut to (re)create a paragraph of a certain type and it should use the same permissions, otherwise it might be confusing and counter-productive.

From my perspective, you shouldn't make it more complicated for you as needed. :) I'd be fine to simply have it in general...

justin2pin’s picture

I've already seen a number of instances where LP is being used in ways I had not foreseen, planned, or intended that I feel strongly there needs to be some ability to restrict this feature. One simple example: we're using LP on a project right now where some editors have the ability to build pages, others have only the ability to edit individual paragraphs. I also worry that we will continue to identify additional features that are useful to some, but not necessarily to others, and may clutter the already somewhat complex interface. So... I think we just need a way for site-builders / developers to turn this off.

I think the simplest solution is adding a permission to the "Layout Paragraphs Permissions" module for controlling this. This will also provide a fairly straightforward example for using the API to limit access where needed, meaning developers can limit access based on other more complex criteria if they need to.

End result:

  • "Duplicate" is enabled by default.
  • The feature can turned off for specific roles using the Layout Paragraphs Permissions submodule.
  • Developers can use the APIs to turn off the feature for more specific contexts as needed.
justin2pin’s picture

Also: I think MR45 is pretty close now - we just needed automated tests.

justin2pin’s picture

Just added a simple test for duplicating a test component and duplicating a two-column section that contains two text components. Once this passes tests, I'll push to dev.

We can continue to discuss points from comments #23-#26, but I don't think that needs to block this from being added.

Thanks everybody.

justin2pin’s picture

Status: Needs review » Fixed
mrpauldriver’s picture

Great. Thanks everyone for working on this.

anybody’s picture

Whao great work! We'll make a larger test run on beta6 / rc0 as soon as it's out and provide further feedback!

layout_paragraphs 2.x is definitely a wonderful Christmas present for Drupal! Druplicon will be happy under the Christmas tree ;)

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.