Closed
Description
@derrabus Am I right that connecting an EnumType
form field with multiple
to an entity is not straightforward?
Since you can't define an array of enums in the entity, the field looks something like this:
#[ORM\Column(type: Types::SIMPLE_ARRAY)]
private array $features = [];
But in order to hydrate the array items as enum (not as string), you need a DataTransformer on the form field, right?
What do you think about adding a full example at https://symfony.com/doc/current/reference/forms/types/enum.html#multiple ?
Due to the DataTransformer, the validation rule you suggested at symfony/symfony#43047 (comment) isn't working, so I'm guessing the only way to get validation on the entity is:
#[Assert\Choice(callback: [Features::class, 'values'], multiple: true)]
... with this in the enum:
public static function values(): array
{
return array_column(self::cases(), 'value');
}