Use EnumType in form instead of ChoiceType for field genderTranslation

This commit is contained in:
Julie Lenaerts 2024-10-01 11:38:43 +02:00
parent d61c090cee
commit e6bfcddae2

View File

@ -8,6 +8,7 @@ use Chill\MainBundle\Entity\GenderIconEnum;
use Chill\MainBundle\Form\Type\TranslatableStringFormType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\EnumType;
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
@ -21,18 +22,25 @@ class GenderType extends AbstractType
->add('label', TranslatableStringFormType::class, [
'required' => true,
])
/* ->add('icon', EnumType::class, [
'class' => GenderIconEnum::class,
'label_html' => true,
'expanded' => false,
'mapped' => true,
])*/
->add('icon', ChoiceType::class, [
'choices' => GenderIconEnum::cases(),
'expanded' => true,
'multiple' => false,
'mapped' => true,
'label' => 'Select Gender Icon',
'choice_label' => fn(GenderIconEnum $enum) => '<i class="' . strtolower($enum->value) . '"></i>',
'choice_value' => fn(?GenderIconEnum $enum) => $enum ? $enum->value : null,
'label' => 'gender.admin.Select Gender Icon',
'label_html' => true,
])
->add('genderTranslation', ChoiceType::class, [
'choices' => GenderEnum::cases(),
'choice_label' => fn(GenderEnum $enum) => ucfirst(strtolower($enum->name)),
'choice_value' => fn(?GenderEnum $enum) => $enum ? $enum->value : null,
'data_class' => null,
->add('genderTranslation', EnumType::class, [
'class' => GenderEnum::class,
'label' => 'gender.admin.Select Gender Translation',
])
->add('active', ChoiceType::class, [
'choices' => [