If the Field Collection contains Entity References, when the 'Add another item' button is clicked, a new row is added, but all values for the Entity Reference (for all rows) are lost.

The Entity Reference values use a Select list widget. The values to build the Select list use an Entity Reference View, with a contextual filter, to build the list of possible references. The contextual filter in the View uses a default value, and I've tried using a URL argument and an OG context. Once the 'Add another' button is pressed this contextual filter value is lost, so the View returns it's fallback value (ie, the filter value does not validate); if this fallback is hide all values, then the Select list has no values to select, and the entity reference value is stripped from each row. And I've also tried Autocomplete widget, but this fails too.

So where has this contextual filter value gone when the field collection table is rebuilt? Is this a Field Collection (rather than an FCT) issue? I would have thought a URL value would be fairly robust...

The temporary workaround I have at the moment is to set the Views contextual filter fallback value to serve up all values - but this won't be practical once live.

There seem to be a lot of Issues related to how the table is rebuilt once 'Add another' is clicked. I've found the problem, but no idea of a solution. Grateful for any thoughts.

Comments

robcarr’s picture

Project: Field Collection Table » Field collection
Version: 7.x-1.x-dev » 7.x-1.0-beta7

I've since found that this issue is related to Field Collection (not just the Field Collection Table).

I've changed the contextual filter to use the URL as the argument. However, this argument value is lost as soon as another row is added to the Field Collection, so the View [generating the list of entity references] is corrupted.

leeresglas’s picture

I can confirm the problem. Removing the contextual filter or setting it to a fixed value "solves" the problem.

leeresglas’s picture

I wrote a patch, that resolves the issue in my case. I posted it in https://drupal.org/node/1688332#comment-8786457 as it is related to other issues of EntityReference. Basically the problem boils down to the entity-reference not getting access to the host entity (as arrrgh already suggested).

robcarr’s picture

Status: Active » Closed (duplicate)

Thanks @leeresglas - the issue at #1688332: Entity Reference view to populate select list for reference field => only one result when using a contextual filter was exactly the problem I had, relating to an entity reference list of users. The patch worked just fine. Thanks :)