src/Form/RegistrationFormType.php line 16

  1. <?php
  2. namespace App\Form;
  3. use App\Entity\User;
  4. use Symfony\Component\Form\AbstractType;
  5. use Symfony\Component\Form\FormBuilderInterface;
  6. use Symfony\Component\Validator\Constraints\IsTrue;
  7. use Symfony\Component\Validator\Constraints\Length;
  8. use Symfony\Component\Validator\Constraints\NotBlank;
  9. use Symfony\Component\OptionsResolver\OptionsResolver;
  10. use Symfony\Contracts\Translation\TranslatorInterface;
  11. use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
  12. use Symfony\Component\Form\Extension\Core\Type\PasswordType;
  13. class RegistrationFormType extends AbstractType
  14. {
  15.     public function __construct(private TranslatorInterface $translator)
  16.     {
  17.     }
  18.     public function buildForm(FormBuilderInterface $builder, array $options): void
  19.     {
  20.         $builder
  21.             ->add('first_name'null, ['label' => $this->translator->trans('Prénom')])
  22.             ->add('last_name'null, ['label' => $this->translator->trans('Nom')])
  23.             ->add('email')
  24.             ->add('plainPassword'PasswordType::class, [
  25.                 // instead of being set onto the object directly,
  26.                 // this is read and encoded in the controller
  27.                 'mapped' => false,
  28.                 'attr' => ['autocomplete' => 'new-password'],
  29.                 'constraints' => [
  30.                     new NotBlank([
  31.                         'message' => $this->translator->trans('Veuillez entrer un mot de passe'),
  32.                     ]),
  33.                     new Length([
  34.                         'min' => 6,
  35.                         'minMessage' => $this->translator->trans('Votre mot de passe doit comporter au moins {{ limit }} caractères'),
  36.                         // max length allowed by Symfony for security reasons
  37.                         'max' => 4096,
  38.                     ]),
  39.                 ],
  40.             ])
  41.             ->add('agreeTerms'CheckboxType::class, [
  42.                 'mapped' => false,
  43.                 'constraints' => [
  44.                     new IsTrue([
  45.                         'message' => $this->translator->trans(' Vous devriez accepter nos conditions'),
  46.                     ]),
  47.                 ],
  48.             ])
  49.         ;
  50.     }
  51.     public function configureOptions(OptionsResolver $resolver): void
  52.     {
  53.         $resolver->setDefaults([
  54.             'data_class' => User::class,
  55.         ]);
  56.     }
  57. }