Problem/Motivation
In case of an entity with an entity reference field containing the entity itself, the entity is cloned three times.
Step to reproduce
With standard installation:
- Add an entity reference field to the article content type
- Create a new article
- Save
- Edit the article
- Reference the article itself in the entity reference field
- Save
- Clone
The content is cloned three times:
- 2 with "- cloned" label
- 1 without "- cloned" label
| Comment | File | Size | Author |
|---|---|---|---|
| #19 | entity-clone-avoid-update-title-twice-from-unwanted-redirect-3030806-19.patch | 1.04 KB | vishnutrz |
Comments
Comment #2
vpeltot commentedHere a patch to solve this.
Comment #4
vpeltot commentedComment #6
vpeltot commentedComment #8
vpeltot commentedComment #9
vpeltot commentedAdd tests to cover this issue.
Comment #10
vpeltot commentedRe-roll
Comment #11
vpeltot commentedThe same patch with coding standards issues fixed.
Comment #12
mars0test commentedRTBC
After testing all seems good for me !
Comment #13
mars0test commentedComment #15
vpeltot commentedCommited !
Comment #17
dksdev01 commentedLooks after this change, hook_entity_presave is being called twice on every clone. thanks
Comment #18
akalam commentedThis change is also causing a unneeded redirect whenever you clone a node if you have installed the redirect module and configured in "automatic" mode.
Is really needed to save the cloned entity twice? Maybe we can add the cloned entity to the $already_cloned as a reference.
Comment #19
vishnutrz commentedWhen we have entity clone module and redirect module with "Automatically create redirects when URL aliases are changed" enable. We can see unwanted redirect create when clone the node due to update in the label "- cloned" on save the entity second time.
We can avoid this by change the label at initial entity save itself.
Attached is a simple patch that fixes this.