diff --git a/src/Plugin/Field/FieldWidget/Select2EntityReferenceWidget.php b/src/Plugin/Field/FieldWidget/Select2EntityReferenceWidget.php index bea14c3c..d7a676b7 100644 --- a/src/Plugin/Field/FieldWidget/Select2EntityReferenceWidget.php +++ b/src/Plugin/Field/FieldWidget/Select2EntityReferenceWidget.php @@ -219,7 +219,7 @@ protected static function prepareFieldValues(array $values, array $element) { /** @var \Drupal\Core\Entity\EntityReferenceSelection\SelectionInterface $handler */ $handler = \Drupal::service('plugin.manager.entity_reference_selection')->getInstance($handler_settings); - $options = static::getValidReferenceableEntities(array_keys(OptGroup::flattenOptions($element['#options'])), $handler_settings); + $options = empty($element['#options']) ? [] : static::getValidReferenceableEntities(array_keys(OptGroup::flattenOptions($element['#options'])), $handler_settings); $items = []; foreach ($values as $value) { if (isset($options[$value])) {