Would be great if, comparable to edit-form and delete-form, an entity could declare a duplicate-form link, and receive a route, local task, form, etc.

Core has a problem in this area worth solving, it is not possible to react to an entity being duplicated. Only the regular save hooks are fired, which give no info on what the original entity was. It would be great if we could figure out a workaround for that as well, so that we can respond to the duplication. For example, when duplicating a bundle entity it is desirable to clone the attached fields and displays.
The cleanest way would probably be to invoke a hook_entity_duplicate() from a trait that can be used form any entity form.

Comments

bojanz created an issue. See original summary.

bojanz’s picture

Adding core issue for the related problem.

hchonov’s picture

I think that we need some form of cascade - for example in the case of nested entity structures, where the referenced entities "might" need to be duplicated as well.

The best would be if we could automate the process without the need to implement any hooks manually - for example if we could find out which referenced entities or dependencies are unique to the current entity and duplicate them as well.

bojanz’s picture

Status: Active » Needs review
StatusFileSize
new32.37 KB

WIP.

Adds an explicit "duplicate" access operation with matching permissions. Felt cleaner than abusing create/update.

bojanz’s picture

StatusFileSize
new39.33 KB

This should be the final patch.

Cleaned up the EntityDuplicateTrait a bit. Added an automatic "Duplicate" operation. Added a test.

bojanz’s picture

StatusFileSize
new47.36 KB

Fixed test.
Fixed the permission logic to only provide duplicate permissions if there is a duplicate form, which is cleaner.

  • bojanz committed 753ed89 on 8.x-1.x
    Issue #3023884 by bojanz: Add a UI for duplicating entities
    
bojanz’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

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