On EntityReference field: InvalidArgumentException: The #default_value property has to be an entity object or an array of entity objects

Created on 16 August 2021, over 3 years ago
Updated 12 January 2025, 3 months ago

I added a view to a field. The view has an entity reference autosuggest field as exposed filter. The field is a basefield of a custom entity so maybe this issue might be related to this?! When I want to edit the field in the node edit form (the views reference field is part of paragraph which is part of a node) I see the ajax throbber but it disappears and nothing happens. When I have a look in the watchdog entries I find the following:

InvalidArgumentException: The #default_value property has to be an entity object or an array of entity objects. in Drupal\Core\Entity\Element\EntityAutocomplete::valueCallback() (Zeile 114 in C:\wamp64\www\awdrupal\httpdocs\core\lib\Drupal\Core\Entity\Element\EntityAutocomplete.php).

I used the ViewsReferenceExposedFilters class already in a local copy of the original viewsreference module. The code was added before all the exposed filter was forked into this custom module. To stay up-to-date I know deleted this local copy of this module and installed viewsreference and viewsreference_filter with Composer. I describe this because I found some code in my old local viewsreference module which solves this - and I am quite sure that this code snippet comes from somewhere in the viewsreference inssue queue. I will share it here with a patch but I think it is not my code

🐛 Bug report
Status

Active

Version

1.0

Component

Code

Created by

🇩🇪Germany tobiberlin Berlin, Germany

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024