eca_form: Exception on form fields that require an entity as default value

Issue information

From user: FloGe

Related to !204 (merged)

Contribution record

Fork management

Problem/Motivation

When I wanted to prepopulate an entit reference field with eca and I used the node id for the value i got an error:

InvalidArgumentException: The #default_value property has to be an entity object or an array of entity objects. in Drupal\Core\Entity\Element\EntityAutocomplete::valueCallback() (line 114 of /var/www/editoring.smartctiesconsulting.eu/web/core/lib/Drupal/Core/Entity/Element/EntityAutocomplete.php).

So I tried to load the node before and then set the default value to [loaded_node] but I got the same error again.

Checking FormFieldDefaultValue I found that [loaded_node] was replaced by the nid from the token service.

Proposed resolution

Check if the widget is an entity reference autocomplete and load referenced entity (see attached patch)

Edited by drupalbot
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information