entity_autocomplete support

Created on 13 May 2022, over 2 years ago
Updated 1 February 2024, 11 months ago

Currently entity_autocomplete field type is not supported.

Form example:

    $form['multivalue'] = [
      '#type' => 'multivalue',
      '#title' => 'Title',
      '#cardinality' => -1,
      '#default_value' => $default_value,
      'entity' => [
        '#type' => 'entity_autocomplete',
        '#target_type' => 'node',
        '#selection_settings' => [
          'target_bundles' => ['article'],
        ],
        '#validate_reference' => TRUE,
        '#title' => 'Entity',
      ];
    ];

After form submission default value is saved in the form. But entity_autocomplete expects an object there instead of an integer.

The following exception is triggered:

The #default_value property has to be an entity object or an array of entity objects.

See \Drupal\Core\Entity\Element\EntityAutocomplete::valueCallback()

Suggestion: add an additional #process method to the field and load related entities.

Feature request
Status

Needs review

Version

1.0

Component

Code

Created by

🇦🇹Austria a.milkovsky UTC +2

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