src/Form/ColleagueBasicType.php line 15

  1. <?php
  2. namespace App\Form;
  3. use App\Entity\Colleague;
  4. use Symfony\Component\Form\AbstractType;
  5. use Symfony\Component\Form\FormBuilderInterface;
  6. use Symfony\Component\Validator\Constraints\File;
  7. use Symfony\Component\OptionsResolver\OptionsResolver;
  8. use Symfony\Contracts\Translation\TranslatorInterface;
  9. use Symfony\Component\Form\Extension\Core\Type\FileType;
  10. use Symfony\Component\Form\Extension\Core\Type\TextType;
  11. use Symfony\Component\Form\Extension\Core\Type\EmailType;
  12. class ColleagueBasicType extends AbstractType
  13. {
  14.     public function __construct(private TranslatorInterface $translator)
  15.     {
  16.     }
  17.     public function buildForm(FormBuilderInterface $builder, array $options): void
  18.     {
  19.         $builder
  20.             ->add('first_name'TextType::class, [
  21.                 'label' => $this->translator->trans('Prénom'),
  22.                 'required' => true,
  23.                 'attr' => [
  24.                     'class' => 'form-control',
  25.                     'placeholder' => ''
  26.                 ],
  27.                 'help' => ''
  28.             ])
  29.             ->add('last_name'TextType::class, [
  30.                 'label' => $this->translator->trans('Nom'),
  31.                 'required' => true,
  32.                 'attr' => [
  33.                     'class' => 'form-control',
  34.                     'placeholder' => ''
  35.                 ],
  36.                 'help' => ''
  37.             ])
  38.             ->add('email'EmailType::class, [
  39.                 'invalid_message' => $this->translator->trans('Email non valid'),
  40.                 //'Email not valid',
  41.                 'required' => false,
  42.                 'label' => $this->translator->trans('Email'),
  43.                 //'Email',
  44.                 'attr' => [
  45.                     'class' => 'form-control',
  46.                     'placeholder' => ''
  47.                 ],
  48.                 'help' => ''
  49.             ])
  50.             ->add('phone'TextType::class, [
  51.                 'label' => $this->translator->trans('Téléphone'),
  52.                 'required' => false,
  53.                 'attr' => [
  54.                     'class' => 'form-control',
  55.                     'placeholder' => ''
  56.                 ],
  57.                 'help' => ''
  58.             ])
  59.             ->add('mobile'TextType::class, [
  60.                 'label' => $this->translator->trans('Mobile'),
  61.                 //'Mobile',
  62.                 'required' => false,
  63.                 'attr' => [
  64.                     'class' => 'form-control',
  65.                     'placeholder' => ''
  66.                 ],
  67.                 'help' => ''
  68.             ])
  69.             ->add('job'TextType::class, [
  70.                 'label' => $this->translator->trans('Emploi'),
  71.                 'required' => false,
  72.                 'attr' => [
  73.                     'class' => 'form-control',
  74.                     'placeholder' => ''
  75.                 ],
  76.                 'help' => ''
  77.             ])
  78.             ->add('photo'FileType::class, [
  79.                 'attr' => [
  80.                     'class' => 'form-control',
  81.                     'placeholder' => ''
  82.                 ],
  83.                 'label' => $this->translator->trans('Photo d\'identité'),
  84.                 'mapped' => false,
  85.                 'required' => false,
  86.                 'constraints' => [
  87.                     new File([
  88.                         'maxSize' => '2048k',
  89.                         'mimeTypes' => [
  90.                             'image/*',
  91.                         ],
  92.                         'mimeTypesMessage' => $this->translator->trans('Veuillez télécharger une image valide'),
  93.                     ])
  94.                 ],
  95.             ])
  96.         ;
  97.     }
  98.     public function configureOptions(OptionsResolver $resolver): void
  99.     {
  100.         $resolver->setDefaults([
  101.             'data_class' => Colleague::class,
  102.         ]);
  103.     }
  104. }