Closed (fixed)
Project:
Entity Clone
Version:
8.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
14 Sep 2016 at 18:24 UTC
Updated:
11 May 2020 at 16:21 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
ruloweb commentedComment #5
ruloweb commentedNew patch. This one adds 4 events:
PRE_CLONE and POST_CLONE events run inside submitForm() method, before/after cloneEntity() method.
PRE_SAVE and POST_SAVE events run inside cloneEntity() method, before/after save() method. If you create an event subscriber which calls to cloneEntity(), this event turns recursive.
I managed to create a recursive solution for cloning Paragraphs and Field collections with these two last events #2706639-18: Support for sub-entity cloning.
Comment #8
erik frèrejeanI actually was just working on a very similar patch, but going the "hook" way, using hooks very similar to the regular "presave"/"update" hooks. Just applied the patch in #5, which works like a charm. I however only have a need for the
PRE_SAVEevent, so haven't tested the others.Comment #9
vpeltot commentedI'm OK to add the two
PRE_CLONEandPOST_CLONEevents.But for the
PRE_SAVEand thePOST_SAVEI think it's the core responsability to dispatch all entity operations (#2551893: Add events for matching entity hooks)Rename the
Eventsnamespace and directory toEvent(to respect all core modules subdirectory definition)Comment #10
vpeltot commentedComment #11
vpeltot commentedComment #12
erik frèrejean@vpeltot, with regard to your
PRE_SAVE/POST_SAVEcomment I agree that these should be emitted by core, however my case (and I'm probably not the only one) I need to perform some changes on the entity pre save but only when a clone is happening. When relying on the core pre save action there is no way AFAIK to recognize that the entity is created from the clone action.Comment #13
colan#12: To handle that, I'm not sure if we should re-add the events or add something to the entity so that we know it's being cloned. Let's commit the other stuff first as we know we definitely need it. Then we can keep talking about this other thing.
I've made the following changes to match the style guidelines:
Comment #14
colanSome of the
src/Form/EntityCloneForm.phpincludes conflict with (and are already handled by) #2908414: Error on abort and redirects - one patch to solve everything so that needs to be applied first. Here's what was changed. I can't run a real interdiff as it doesn't work.Tests will probably fail until #2908414: Error on abort and redirects - one patch to solve everything is committed.
Comment #16
colanResetting status for humans as we're expecting this to fail for the time being.
Comment #18
vpeltot commentedThanks @all
Comment #19
vpeltot commentedComment #20
cosmicdreams commentedSo happy to have found this.
Is there any documentation that describes how you can integrate a custom entity into entity clone using these events? Would be great to see a code example of this.
Comment #21
jasonawantDocumentation patch found in #3063185: Add documentation for dispatched events