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

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jamsilver’s picture

Assigned: jamsilver » Unassigned
Status: Needs work » Needs review
FileSize
2.08 KB

It 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?

jamsilver’s picture

Assigned: Unassigned » jamsilver
Status: Needs review » Needs work

Whoops, uploaded the wrong patch. This doesn't quite work.

jamsilver’s picture

Assigned: jamsilver » Unassigned
Status: Needs work » Needs review
FileSize
579 bytes

OK, 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 =).

cocoshogo’s picture

I 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?

jamsilver’s picture

It 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!

bojanz’s picture

Status: Needs review » Fixed

This looks reasonable. Can't hurt, in any case. Committed, thanks!

bojanz’s picture

Note that I accidentally committed #1899946: Add Reference Form Alter Hook together with this fix.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

jubileesw’s picture

Has 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.

ABaier’s picture

Issue summary: View changes

Unfortunately 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.

ABaier’s picture

Version: 7.x-1.1 » 7.x-1.6
Status: Closed (fixed) » Active
Robert Castelo’s picture

Issue 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

Erik.Johansson’s picture

I'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.

rich.3po’s picture

Hi, 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 ...