The multi-valued IEF widget puts the add form in the exact same parent-location in the form/form values array structure. This mixes badly with the way the field_collection embed widget tries to gather it's values. The specific problem is:
Set up
1. Put a field_collection field (using the embed widget) on the referenced entity type - e.g. taxonomy term.
2. Add an entity_reference/multi-valued IEF widget on the host entity type configured to reference the above- e.g. Node
Steps to reproduce
1. Create/Edit your host entity form (e.g. Node add)
2. Create 1 new term inline populate your field collection values, save it
3. (Without saving the node) Create a second new term inline.
Expected results
1. A nice blank term add form appears inline ready for me to fill in
Actual results
1. The form is actually prefilled with the values I already put in the first form.
2. Other bad confusions between which values belong to which.
Patch to follow
Comments
Comment #1
jamsilver CreditAttribution: jamsilver commentedIt is sufficient to tweak the location of the add form in the form structure to make it unique per each different value. This seems to work for me!
Note, I haven't bothered to make this change for the single-value widget as, by design, it can only hold one value, right?
Comment #2
jamsilver CreditAttribution: jamsilver commentedWhoops, uploaded the wrong patch. This doesn't quite work.
Comment #3
jamsilver CreditAttribution: jamsilver commentedOK, even simpler solution was needed. Turns out that inline entity form's 'cleaning up of form state' on entity form submit just wasn't quite doing the full job. One extra line needed =).
Comment #4
cocoshogo CreditAttribution: cocoshogo commentedI have embedded IEF for entities within an entity. and I get the same result. I get duplicated entities created that are copies of the first entity. Does this patch fix this?
Comment #5
jamsilver CreditAttribution: jamsilver commentedIt does for me! Could you possibly apply the patch and test it?
See http://drupal.org/patch/apply
If it works for you you could change the status of this ticket to "reviewed and tested by the community" and then the module maintainer may commit it!
Comment #6
bojanz CreditAttribution: bojanz commentedThis looks reasonable. Can't hurt, in any case. Committed, thanks!
Comment #7
bojanz CreditAttribution: bojanz commentedNote that I accidentally committed #1899946: Add Reference Form Alter Hook together with this fix.
Comment #9
jubileesw CreditAttribution: jubileesw commentedHas anyone seen a similar issue with nodes specifically? I don't think the patched code above is invoked if the entityreference is pointing at standard content or a taxonomy term instead of a custom entity.
Comment #10
ABaier CreditAttribution: ABaier commentedUnfortunately this issue still seems to be present, at least for images. I am using version 7.x-1.6.
In my case I have a content type including an entity reference (inline entity form, multiple values) targeting a content type including a field collection with some text fields and a multi value image field. Like stated in this issue the image field is prefilled with the values I put in the first form. The other fields are all good and empty.
It would not be very user friendly to save the parent node first and then come back to upload the individual images.
Could somebody please revise this behavior?
Thanks in advance.
Comment #11
ABaier CreditAttribution: ABaier commentedComment #12
Robert Castelo CreditAttribution: Robert Castelo as a volunteer and at Code Positive Services commentedIssue is caused by the way IEF stores entities in an array with a IEF ID as the key, when the IEF ID is generated it doesn't use the delta of the parent entity reference that the child IEF widget is in. This normally works ok, but when a Field Collection is thrown into the mix the same IEF ID is generated even if child IEF widgets are in different parent nodes.
Attached patch calculates a delta based on number of nodes in the parent IEF widget and uses the delta to generate a new IEF ID when a new child IEF widget is added.
This solves the issue of duplicate content being added to new child nodes, and also all the IEF buttons work (edit, remove, update, save, cancel,...), as well as re-ordering of child nodes within the IEF widget.
Issues still not solved:
* Save a parent node without first saving child node - child node is not saved
* Submit page form without first saving child node - child node is not saved
* Field Collection 'Add another item' - duplicate content is in the new item
Comment #13
Erik.Johansson CreditAttribution: Erik.Johansson commentedI'm experiencing the same issue as #10. I've a entity reference field that allows multiple values with the widget "Inline entity form - Multiple values" inside a Field collection. In my case I've multiple field collection items on a node, each item has a node referenced through the entity reference field.
The structure looks like this:
Field collection item #1
Entity reference: Entity 1
Field collection item #2
Entity reference: Entity 2
When I remove Field collection item #1 the structure now looks like this:
Field collection item #2
Entity reference: Entity 1
Field collection item #2 entity reference value has been replaced with the value from Field collection item #1.
Comment #14
rich.3po CreditAttribution: rich.3po commentedHi, i'm experiencing this same issue on D8, has anyone had any luck applying the patch there, or know if theres a separate issue for it? (i've had a dig but can't see one)
I"m going to attempt to port the patch ...