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
Comment | File | Size | Author |
---|---|---|---|
#24 | fix-param-errors-1753774-7.1.1.patch | 2.06 KB | michel.g |
#5 | 1753774-5_fix_array_param_errors.patch | 2.11 KB | tedfordgif |
Comments
Comment #1
k.skarlatos CreditAttribution: k.skarlatos commentedI just found out that the same problem happens when i use an entity reference field filtered by a view inside a relation add form.
Comment #2
MustangGB CreditAttribution: MustangGB commentedIGNORE
Comment #3
lolmaus CreditAttribution: lolmaus commentedTwo months already, any solution on this one?
Comment #4
derekw CreditAttribution: derekw commentedSame problem here -- entity reference field, with contextual view filter. Does not involve field collection module.
Comment #5
tedfordgif CreditAttribution: tedfordgif commentedHere's a simple patch that addresses the issues for me, but needs more thorough review.
Comment #6
Fidelix CreditAttribution: Fidelix commentedThis fixed it for me. It's a pretty simple change and from what I see it's ready...
Comment #7
k.skarlatos CreditAttribution: k.skarlatos commentedI 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.
Comment #8
operations CreditAttribution: operations commented#5 patch is working good. It removes the warnings of array_flip and array_keys when using entity reference views with dynamic contextual filter.
Comment #9
ckng#5 is good.
#7 obviously a different issue.
Comment #10
liquidcms CreditAttribution: liquidcms commentedpatch in #5 worked for me.. :)
Comment #11
jenniferannwalsh CreditAttribution: jenniferannwalsh commented#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
Comment #12
MustangGB CreditAttribution: MustangGB commentedThis should be fixed in dev.
Comment #13
milos.kroulik CreditAttribution: milos.kroulik commentedThe patch from #5 still applies to latest dev.
Comment #14
amitaibuMerged, thanks.
Comment #16
maximpodorov CreditAttribution: maximpodorov commentedThe similar issue: #2118361: Execution of view can return NULL.
Comment #17
OFF CreditAttribution: OFF commentedproblem still in latest dev
Comment #18
OFF CreditAttribution: OFF commentedComment #19
Alauddin CreditAttribution: Alauddin commentedLatest dev worked for me
Comment #20
tascThe 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?
Comment #21
kle CreditAttribution: kle commentedif 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 !Comment #22
MustangGB CreditAttribution: MustangGB commentedPatch 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.
Comment #24
michel.g CreditAttribution: michel.g at Randstad Digital for Government of Flanders commentedAdded 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.