I dont know if this a bug for entityreference, field collection or views, but i am posting it here because the warnings i get are from the entityreference module.

I have an entity reference field inside a field collection.
That entity reference field is filtered by an entity reference view. When i press the "add new" or "remove" buttons in the field collection i get these warnings:

Warning: array_flip() expects parameter 1 to be array, null given in entityreference_field_validate() (line 224 of /srv/http/epik/sites/all/modules/entityreference/entityreference.module).
Warning: array_keys() expects parameter 1 to be array, null given in EntityReference_SelectionHandler_Views->validateReferencableEntities() (line 131 of /srv/http/epik/sites/all/modules/entityreference/plugins/selection/EntityReference_SelectionHandler_Views.class.php).
Warning: array_diff_key(): Argument #2 is not an array in entityreference_field_validate() (line 224 of /srv/http/epik/sites/all/modules/entityreference/entityreference.module).
Warning: array_flip() expects parameter 1 to be array, null given in entityreference_field_validate() (line 224 of /srv/http/epik/sites/all/modules/entityreference/entityreference.module).
Warning: array_keys() expects parameter 1 to be array, null given in EntityReference_SelectionHandler_Views->validateReferencableEntities() (line 131 of /srv/http/epik/sites/all/modules/entityreference/plugins/selection/EntityReference_SelectionHandler_Views.class.php).

This causes all of the entity reference fields to lose their values and display only the "none" value.

This only happens when the view contains a contextual filter. If there is no contextual filter everything works fine.

Tested with latest stable and dev versions of views, entity reference, field collection, entity api, php 5.3 and php 5.4

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

k.skarlatos’s picture

I just found out that the same problem happens when i use an entity reference field filtered by a view inside a relation add form.

MustangGB’s picture

IGNORE

lolmaus’s picture

Two months already, any solution on this one?

derekw’s picture

Same problem here -- entity reference field, with contextual view filter. Does not involve field collection module.

tedfordgif’s picture

Version: 7.x-1.x-dev » 7.x-1.0
Status: Active » Needs work
FileSize
2.11 KB

Here's a simple patch that addresses the issues for me, but needs more thorough review.

Fidelix’s picture

Status: Needs work » Needs review

This fixed it for me. It's a pretty simple change and from what I see it's ready...

k.skarlatos’s picture

I get these warnings and a "An illegal choice was detected. Please contact your administrator" message.
This happens when
1) I have an entity reference field (filtered by views)
2) A date field
3) I use date repeat
4) I select Include dates and add 2 or more dates.

This disappears if i remove the entity reference field. Also this patch does not fix that problem for me.

operations’s picture

#5 patch is working good. It removes the warnings of array_flip and array_keys when using entity reference views with dynamic contextual filter.

ckng’s picture

Status: Needs review » Reviewed & tested by the community

#5 is good.
#7 obviously a different issue.

liquidcms’s picture

patch in #5 worked for me.. :)

jenniferannwalsh’s picture

#5 worked for me to stop the warnings above as well as this one too:
Warning: array_diff_key(): Argument #2 is not an array in entityreference_field_validate()
I applied it to 7.x-1.1

MustangGB’s picture

Version: 7.x-1.0 » 7.x-1.x-dev

This should be fixed in dev.

milos.kroulik’s picture

The patch from #5 still applies to latest dev.

amitaibu’s picture

Status: Reviewed & tested by the community » Fixed

Merged, thanks.

  • amitaibu committed ab62b9a on 7.x-1.x authored by tedfordgif
    Issue #1753774 by tedfordgif: Multiple warnings when using entity...
maximpodorov’s picture

OFF’s picture

problem still in latest dev

OFF’s picture

Status: Fixed » Active
Alauddin’s picture

Latest dev worked for me

tasc’s picture

The patch in #5 works on 7.x-1.1 for me too. It stops validation and thus no warning is shown, but I wonder if this is the right way to address the issue?

kle’s picture

if an entity reference field is filtered by a view, the view is called twice:
1. via AJAX to search for possible results -> getReferencableEntities()
2. after submit for validation -> validateReferencableEntities()

If the field-settings view-arg is empty, NO argument is given to the view. You have to use a hook:

You can use hook_views_pre_view() to add some arguments to the autocomplete-view. But dont forget: if your arguments depend on the path, the path in case 1. and 2. are different !

MustangGB’s picture

Status: Active » Fixed

Patch has been committed and confirmed working in dev, so restoring status, probably best to open a support request with repro steps if you're still having problems.

Status: Fixed » Closed (fixed)

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

michel.g’s picture

Added a patch for the 7.x-1.1 version, since the project I'm working on does not have the module updated, this needs to be planned in.