src/Form/RegistrationFormType.php line 21

Open in your IDE?
  1. <?php
  2. namespace App\Form;
  3. use App\Entity\User;
  4. use Symfony\Component\Form\AbstractType;
  5. use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
  6. use Symfony\Component\Form\Extension\Core\Type\PasswordType;
  7. use Symfony\Component\Form\FormBuilderInterface;
  8. use Symfony\Component\OptionsResolver\OptionsResolver;
  9. use Symfony\Component\Validator\Constraints\IsTrue;
  10. use Symfony\Component\Validator\Constraints\Length;
  11. use Symfony\Component\Validator\Constraints\NotBlank;
  12. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  13. use Symfony\Component\Validator\Constraints\File;
  14. use Symfony\Component\Form\Extension\Core\Type\FileType;
  15. use Vich\UploaderBundle\Form\Type\VichFileType;
  16. class RegistrationFormType extends AbstractType
  17. {
  18.     public function buildForm(FormBuilderInterface $builder, array $options): void
  19.     {
  20.         $builder
  21.             ->add('username')
  22.             ->add('plainPassword'PasswordType::class, [
  23.                 // instead of being set onto the object directly,
  24.                 // this is read and encoded in the controller
  25.                 'mapped' => false,
  26.                 'attr' => ['autocomplete' => 'new-password'],
  27.                 'constraints' => [
  28.                     new NotBlank([
  29.                         'message' => 'Please enter a password',
  30.                     ]),
  31.                     new Length([
  32.                         'min' => 6,
  33.                         'minMessage' => 'Your password should be at least {{ limit }} characters',
  34.                         // max length allowed by Symfony for security reasons
  35.                         'max' => 4096,
  36.                     ]),
  37.                 ],
  38.             ])
  39.             ->add('roles'ChoiceType::class, array(
  40.                 'choices'   => array(
  41.                     'ROLE_ADMIN'   => 'ROLE_ADMIN',
  42.                     'ROLE_CANDIDATE'      => 'ROLE_CANDIDATE',
  43.                     'ROLE_TEACHER'      => 'ROLE_TEACHER',
  44.                     'ROLE_AGENT'      => 'ROLE_AGENT'
  45.                 ),
  46.                 'multiple'  => true,
  47.              ))
  48.             
  49.             ->add('nom')
  50.             ->add('prenom')
  51.             ->add('tel')
  52.             ->add('photoDeProfil'FileType::class, [
  53.                 'label' => 'Photo De Profil',
  54.                 // unmapped means that this field is not associated to any entity property
  55.                 'mapped' => false,
  56.                 // make it optional so you don't have to re-upload the PDF file
  57.                 // every time you edit the Product details
  58.                 'required' => false,
  59.                 // unmapped fields can't define their validation using annotations
  60.                 // in the associated entity, so you can use the PHP constraint classes
  61.                 'constraints' => [
  62.                     new File()
  63.                 ],
  64.              ])
  65.             ->add('cv'FileType::class, [
  66.                 'label' => 'Cv',
  67.                 // unmapped means that this field is not associated to any entity property
  68.                 'mapped' => false,
  69.                 // make it optional so you don't have to re-upload the PDF file
  70.                 // every time you edit the Product details
  71.                 'required' => false,
  72.                 // unmapped fields can't define their validation using annotations
  73.                 // in the associated entity, so you can use the PHP constraint classes
  74.                 'constraints' => [
  75.                     new File()
  76.                 ],
  77.              ])
  78.         
  79.         ;
  80.     }
  81.     public function configureOptions(OptionsResolver $resolver): void
  82.     {
  83.         $resolver->setDefaults([
  84.             'data_class' => User::class,
  85.         ]);
  86.     }
  87. }