src/Form/RegistrationFormType.php line 15

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\EmailType;
  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. class RegistrationFormType extends AbstractType
  13. {
  14.     public function buildForm(FormBuilderInterface $builder, array $options): void
  15.     {
  16.         $builder
  17.             ->add('email'EmailType::class, ['label' => 'email'])
  18.             ->add('person'RegistrationPersonType::class)
  19.             ->add('plainPassword'PasswordType::class, [
  20.                 // instead of being set onto the object directly,
  21.                 // this is read and encoded in the controller
  22.                 'mapped' => false,
  23.                 'label' => 'register.password',
  24.                 'attr' => ['autocomplete' => 'new-password'],
  25.                 'constraints' => [
  26.                     new NotBlank([
  27.                         'message' => 'Veuillez insérer un mot de passe',
  28.                     ]),
  29.                     new Length([
  30.                         'min' => 6,
  31.                         'minMessage' => 'Votre mot de passe doit contenir au minimum {{ limit }} caractères',
  32.                         // max length allowed by Symfony for security reasons
  33.                         'max' => 4096,
  34.                     ]),
  35.                 ],
  36.             ])
  37.         ;
  38.     }
  39.     public function getBlockPrefix()
  40.     {
  41.         return 'form'// TODO: Change the autogenerated stub
  42.     }
  43.     public function configureOptions(OptionsResolver $resolver): void
  44.     {
  45.         $resolver->setDefaults([
  46.             'data_class' => User::class,
  47.         ]);
  48.     }
  49. }