I have an entityreference field in a complex form set to create a sets of checkboxes and using a view to select the entities. It works correctly until I use AJAX to load a file in another field. In that case, the form is saved to the cache, then when I click "Save" to save the file, when the system reloads the form from cache it cannot find any valid options (the #options element is an empty array for that field), and issues the Illegal Choice error.

I debugged the form, and saw that at the getReferencableEntities function of EntityReference_SelectionHandler_Views.class.php, before saving to cache the $result of executing the view is empty, whereas in other instances the result always has the (correct) five results and saves just fine.

I've checked the parameters that go into the view in both cases, and they're the same, although they produce different results.

See attached images with a screenshot of PHPStorm debugging, with variables expanded on screen. In one case I have results, in others no results.

NO OPTIONS
NO options

HAS OPTIONS
HAS OPTIONS

Anyone can help, or at least give a hint at where to look to solve the issue?

Thanks.

Comments

pmioni created an issue. See original summary.

pmioni’s picture

Issue summary: View changes
pmioni’s picture

Issue summary: View changes
StatusFileSize
new126.71 KB
new111.44 KB
pmioni’s picture

Issue summary: View changes
ladybug_3777’s picture

Did you resolve this issue? I'm having a similar issue. I have an Entity Reference drop down which provides a list of usernames as well as a file upload field. If I select a user from the drop down and then select and upload a file and click "save" I get the same "An illegal choice has been detected"

If I select a user, select a file but don't click the "upload" button on the file then I do not get the error on save. I suspect the ajax request to do the file upload is causing the issue, but not sure how to resolve it.

This issue seems to have suddenly appeared without any known changes to the system.