Problem/Motivation
When cloning an entity that references a File, the new option to also clone the referenced File is great - but doesn't quite work right. After submitting the form, the referenced File entity is cloned twice - one clone has the copied file URI, another clone has the original file URI. The parent entity references the second, incorrect File clone that points to the original URI.
Data before clone
Node field data file_managed +-----+-----------------------+ +-----+------------------------------+ | nid | field_image_target_id | | fid | filename | uri | +-----+-----------------------+ +-----+------------------------------+ | 1 | 1 | | 1 | test.jpg | public://test.jpg | +-----+-----------------------+ +-----+------------------------------+
Data after clone - expected
Node field data file_managed +-----+-----------------------+ +-----+-----------------------------------------+ | nid | field_image_target_id | | fid | filename | uri | +-----+-----------------------+ +-----+-----------------------------------------+ | 1 | 1 | | 1 | test.jpg | public://test.jpg | | 2 | 2 | | 2 | test.jpg - Cloned | public://test_0.jpg | +-----+-----------------------+ +-----+-----------------------------------------+
Data after clone - actual
Node field data file_managed
+-----+-----------------------+ +-----+-----------------------------------------+
| nid | field_image_target_id | | fid | filename | uri |
+-----+-----------------------+ +-----+-----------------------------------------+
| 1 | 1 | | 1 | test.jpg | public://test.jpg |
| 2 | 3 | | 2 | test.jpg - Cloned | public://test_0.jpg |
+-----+-----------------------+ | 3 | test.jpg | public://test.jpg |
+-----+-----------------------------------------+
Steps to reproduce
Create a node with a File or Image entity reference. Clone the node, including the referenced File.
Proposed resolution
ContentEntityCloneBase::cloneReferencedEntities() assumes that the $cloned_entity object will be modifed in-place by the call to cloneEntity(), which does not in fact happen because of how FileEntityClone::cloneEntity() works. Use the return value of cloneEntity() instead.
Issue fork entity_clone-3379148
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:
- 2.x
changes, plain diff MR !50
- 3379148-refrenced-files-are
changes, plain diff MR !49
Comments
Comment #4
bgreco commentedComment #6
bgreco commentedComment #7
bgreco commentedComment #8
s_leu commentedPatch is solving the problem outlined in the IS for me.
Comment #11
rajeshreeputraChanges looks good, and works as well, merged. Release to follow shortly!