src/Form/CompanyTypeBasicInfos.php line 19

  1. <?php
  2. namespace App\Form;
  3. use App\Entity\Company;
  4. use App\Entity\enums\CompanyCategory;
  5. use Symfony\Component\Form\AbstractType;
  6. use Symfony\Component\Form\FormBuilderInterface;
  7. use Symfony\Component\Validator\Constraints\File;
  8. use Symfony\Component\OptionsResolver\OptionsResolver;
  9. use Symfony\Contracts\Translation\TranslatorInterface;
  10. use Symfony\Component\Form\Extension\Core\Type\EnumType;
  11. use Symfony\Component\Form\Extension\Core\Type\FileType;
  12. use Symfony\Component\Form\Extension\Core\Type\TextType;
  13. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  14. use Symfony\Component\Form\Extension\Core\Type\TextareaType;
  15. use Symfony\Component\Form\Extension\Core\Type\CollectionType;
  16. class CompanyTypeBasicInfos extends AbstractType
  17. {
  18.     public function __construct(private TranslatorInterface $translator)
  19.     {
  20.     }
  21.     public function buildForm(FormBuilderInterface $builder, array $options): void
  22.     {
  23.         $builder
  24.             ->add('name'TextType::class, [
  25.                 'label' => $this->translator->trans('Nom de Crèche'),
  26.                 'required' => true,
  27.                 //'Company name',
  28.                 'attr' => [
  29.                     'class' => 'form-control',
  30.                     'placeholder' => ''
  31.                 ],
  32.                 'help' => ''
  33.             ])
  34.             ->add('type'EnumType::class, [
  35.                 'label' => $this->translator->trans('Type'),
  36.                 'required' => true,
  37.                 'class' => CompanyCategory::class,
  38.                 'attr' => [
  39.                     'class' => 'form-control',
  40.                     'placeholder' => ''
  41.                 ],
  42.                 'help' => '',
  43.                 'choice_label' => fn($choice) => match ($choice) {
  44.                     CompanyCategory::jardin_d_enfants => $this->translator->trans('Jardin d\'enfants'),
  45.                     CompanyCategory::creche => $this->translator->trans('Crèche'),
  46.                     CompanyCategory::etablissement_multi_accueil => $this->translator->trans('Etablissement multi accueil'),
  47.                 },
  48.                 // 'choice_label' => function ($choice, $key, $value) {
  49.                 //     return $value;
  50.                 // },
  51.             ])
  52.             ->add('size'ChoiceType::class, [
  53.                 'label' => $this->translator->trans('Taille'),
  54.                 'required' => false,
  55.                 'attr' => [
  56.                     'class' => 'form-control',
  57.                     'placeholder' => ''
  58.                 ],
  59.                 'help' => '',
  60.                 'choices' => [
  61.                     $this->translator->trans('Petite') => 'petite',
  62.                     $this->translator->trans('Moyenne') => 'moyenne',
  63.                     $this->translator->trans('Grande') => 'grande',
  64.                 ]
  65.             ])
  66.             ->add('description'TextareaType::class, [
  67.                 'label' => $this->translator->trans('Slogan'),
  68.                 'required' => false,
  69.                 'attr' => [
  70.                     'class' => 'form-control',
  71.                     'placeholder' => ''
  72.                 ],
  73.                 'help' => ''
  74.             ])
  75.             // ->add('logo')
  76.             ->add('logo'FileType::class, [
  77.                 'attr' => [
  78.                     'class' => 'form-control',
  79.                     'placeholder' => ''
  80.                 ],
  81.                 'label' => $this->translator->trans('Logo'),
  82.                 'mapped' => false,
  83.                 'required' => false,
  84.                 'constraints' => [
  85.                     new File([
  86.                         'maxSize' => '2048k',
  87.                         'mimeTypes' => [
  88.                             'image/*',
  89.                         ],
  90.                         'mimeTypesMessage' => $this->translator->trans('Veuillez télécharger une image valide'),
  91.                     ])
  92.                 ],
  93.             ])
  94.             ->add('email'TextType::class, [
  95.                 'label' => $this->translator->trans('Email'),
  96.                 'required' => false,
  97.                 'attr' => [
  98.                     'class' => 'form-control',
  99.                     'placeholder' => ''
  100.                 ],
  101.                 'help' => ''
  102.             ])
  103.             ->add('phone'TextType::class, [
  104.                 'label' => $this->translator->trans('Téléphone'),
  105.                 'required' => false,
  106.                 'attr' => [
  107.                     'class' => 'form-control',
  108.                     'placeholder' => ''
  109.                 ],
  110.                 'help' => ''
  111.             ])
  112.             ->add('mobile'TextType::class, [
  113.                 'label' => $this->translator->trans('Mobile'),
  114.                 'required' => false,
  115.                 'attr' => [
  116.                     'class' => 'form-control',
  117.                     'placeholder' => ''
  118.                 ],
  119.                 'help' => ''
  120.             ])
  121.             ->add('fax'TextType::class, [
  122.                 'label' => $this->translator->trans('Fax'),
  123.                 'required' => false,
  124.                 'attr' => [
  125.                     'class' => 'form-control',
  126.                     'placeholder' => ''
  127.                 ],
  128.                 'help' => ''
  129.             ])
  130.         ;
  131.     }
  132.     public function configureOptions(OptionsResolver $resolver): void
  133.     {
  134.         $resolver->setDefaults([
  135.             'data_class' => Company::class,
  136.         ]);
  137.     }
  138. }