diff --git a/src/Field/CollectionField.php b/src/Field/CollectionField.php index 1e253ca0e1..75943e8239 100644 --- a/src/Field/CollectionField.php +++ b/src/Field/CollectionField.php @@ -17,6 +17,7 @@ final class CollectionField implements FieldInterface public const OPTION_ALLOW_ADD = 'allowAdd'; public const OPTION_ALLOW_DELETE = 'allowDelete'; public const OPTION_ENTRY_IS_COMPLEX = 'entryIsComplex'; + public const OPTION_ENTRY_OPTIONS = 'entryOptions'; public const OPTION_ENTRY_TYPE = 'entryType'; public const OPTION_ENTRY_TO_STRING_METHOD = 'entryToStringMethod'; public const OPTION_SHOW_ENTRY_LABEL = 'showEntryLabel'; @@ -42,6 +43,7 @@ public static function new(string $propertyName, $label = null): self ->setCustomOption(self::OPTION_ALLOW_ADD, true) ->setCustomOption(self::OPTION_ALLOW_DELETE, true) ->setCustomOption(self::OPTION_ENTRY_IS_COMPLEX, null) + ->setCustomOption(self::OPTION_ENTRY_OPTIONS, null) ->setCustomOption(self::OPTION_ENTRY_TYPE, null) ->setCustomOption(self::OPTION_ENTRY_TO_STRING_METHOD, null) ->setCustomOption(self::OPTION_SHOW_ENTRY_LABEL, false) @@ -84,6 +86,16 @@ public function setEntryType(string $formTypeFqcn): self return $this; } + /** + * @param array $entryOptions + */ + public function setEntryOptions(array $entryOptions): self + { + $this->setCustomOption(self::OPTION_ENTRY_OPTIONS, $entryOptions); + + return $this; + } + /** * @param string|callable $toStringMethod Either a string with the name of the method to call in the entry object or a callable to generate the string representation of the entry. The callable is passed the value as the first argument and the translator service as the second argument. */ diff --git a/src/Field/Configurator/CollectionConfigurator.php b/src/Field/Configurator/CollectionConfigurator.php index 2da9dd15a9..07ef6c17f8 100644 --- a/src/Field/Configurator/CollectionConfigurator.php +++ b/src/Field/Configurator/CollectionConfigurator.php @@ -56,6 +56,15 @@ public function configure(FieldDto $field, EntityDto $entityDto, AdminContext $c $field->setFormTypeOption('entry_type', $entryTypeFqcn); } + if (null !== $entryOptions = $field->getCustomOptions()->get(CollectionField::OPTION_ENTRY_OPTIONS)) { + $existingEntryOptions = $field->getFormTypeOption('entry_options'); + if (!\is_array($existingEntryOptions)) { + $existingEntryOptions = []; + } + + $field->setFormTypeOption('entry_options', array_replace_recursive($existingEntryOptions, $entryOptions)); + } + $autocompletableFormTypes = [CountryType::class, CurrencyType::class, LanguageType::class, LocaleType::class, TimezoneType::class]; if (\in_array($entryTypeFqcn, $autocompletableFormTypes, true)) { $field->setFormTypeOption('entry_options.attr.data-ea-widget', 'ea-autocomplete');