Needs review
Project:
Entity Clone
Version:
2.x-dev
Component:
Code
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
16 Mar 2018 at 15:14 UTC
Updated:
1 Oct 2025 at 11:01 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
pguillard commentedThis patch is to be applied after #2706639: Support for sub-entity cloning #131
Then I can use a HOOK like that :
Comment #4
pguillard commentedComment #6
partdigital commentedComment #9
partdigital commentedI was running into this issue as well. The entity_clone module does not make it very easy to customize which fields you want to include in the cloning process and which ones you want to exclude. I've created a new MR which introduces a new hook
hook_entity_clone_clonable_fields_alter().How this works is that it scans and caches all the "cloneable" fields. Before that cache is saved though you can manipulate that array of fields with this hook.
Additional changes:
This required refactoring
EntitycloneClonableField, I have added more automated tests to support this refactoring effort. I can also confirm that all existing automated tests are still working.EDIT: It looks like some tests are failing in build that were working on local. Will address.
Other thoughts:
It would be great to be able to exclude/include fields right from the Field UI. For example, perhaps saved as third-party settings.
Comment #11
rajeshreeputra@partdigital, there is an issue #3350358: Option to update entity data before cloning - UI Improvements for providing UI for updating data before cloning, we can utilize that.
Comment #12
partdigital commentedHi @rajeshreeputra, thanks for adding the dependency injection. I had noticed that last night!
https://www.drupal.org/project/entity_clone/issues/3350358 is not quite the same thing as this issue. This ticket is to allow you to specify which fields you want included/excluded in the cloning process. This would not be set by an author. Consider for example a node that has a "featured content" field. When we clone the node we wouldn't want to clone the content referenced in "featured content", this issue allows us to always exclude that field without requiring author input.
This ticket is primarily an API change but expressed in terms of Field UI it would look something like this.
Comment #13
partdigital commentedI pushed up one change that makes it slightly easier to work with the hook. Now you can enable/disable fields like this.
Comment #14
damien laguerre commentedFirst, thanks for your works!
I tried your patch and implemented the function mymodule_entity_clone_clonable_fields_alter(array &$fields)
But that's not enough, for this to work I need to clear the new entity field using a bundle class with a custom createDuplicate:
Otherwise, the field is not cloned by entity_clone, but is already filled by the core duplication.
Comment #15
mably commentedCreated another issue with some pretty generic hooks that could be useful: #3518541: New access hooks to allow fine grained configuration of the clone form
Any feedback will be appreciated.
Comment #16
partdigital commentedI've pushed up an update that addresses a performance issue.
Comment #18
deaom commentedAfter re-basing the tests are failing. It does seem that the circular cloning no longer works as it does not clone that node, just references it. Looking into it, but do not mind if somebody will be faster then me.
Comment #19
deaom commentedTest are now passing, ready for review.
There was an issue where PTs were getting cloned even if excluded, an issue that was already solved in #3397218: Clone form is not respecting 'cloneable_entities' config resulting in memory limit on recursive in ContentEntityCloneFormBase for a custom Entity.. The code for PT handling is from there, adjusted for this code.