Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/Field/CollectionField.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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)
Expand Down Expand Up @@ -84,6 +86,16 @@ public function setEntryType(string $formTypeFqcn): self
return $this;
}

/**
* @param array<string, mixed> $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.
*/
Expand Down
9 changes: 9 additions & 0 deletions src/Field/Configurator/CollectionConfigurator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
Loading