src/Form/RegistrationFormTypeExpert.php line 36

Open in your IDE?
  1. <?php
  2. /*
  3. * Ce fichier est la propriété de l'association (c) Projets Métiers
  4. *
  5. * (c) crée par Jean-Marc CATALA <jeanmmarccatala@gmail.com>
  6. *
  7. */
  8. namespace App\Form;
  9. use App\Entity\Institution;
  10. use App\Entity\User;
  11. use App\Repository\UserRepository;
  12. use Doctrine\ORM\EntityRepository;
  13. use phpDocumentor\Reflection\Types\Null_;
  14. use Symfony\Bridge\Doctrine\Form\Type\EntityType;
  15. use Symfony\Component\Form\AbstractType;
  16. use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
  17. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  18. use Symfony\Component\Form\Extension\Core\Type\EmailType;
  19. use Symfony\Component\Form\Extension\Core\Type\PasswordType;
  20. use Symfony\Component\Form\Extension\Core\Type\RepeatedType;
  21. use Symfony\Component\Form\Extension\Core\Type\TextType;
  22. use Symfony\Component\Form\FormBuilderInterface;
  23. use Symfony\Component\Form\FormError;
  24. use Symfony\Component\Form\FormEvent;
  25. use Symfony\Component\Form\FormEvents;
  26. use Symfony\Component\OptionsResolver\OptionsResolver;
  27. use Symfony\Component\Validator\Constraints\IsTrue;
  28. use Symfony\Component\Validator\Constraints\Length;
  29. use Symfony\Component\Validator\Constraints\NotBlank;
  30. use function date_date_set;
  31. use function dd;
  32. use function in_array;
  33. class RegistrationFormTypeExpert extends AbstractType
  34. {
  35. /**
  36. * @var UserRepository
  37. */
  38. private $userRepository;
  39. public function __construct(UserRepository $userRepository)
  40. {
  41. $this->userRepository = $userRepository;
  42. }
  43. public function buildForm(FormBuilderInterface $builder, array $options)
  44. {
  45. $builder
  46. ->add('email')
  47. ->add('name',TextType::class, array('label' => 'Prénom'))
  48. ->add('firstName',TextType::class, array('label' => 'Nom'))
  49. ->add('agreeTerms', CheckboxType::class, [
  50. 'mapped' => false,
  51. 'label'=> "j'accepte les condition générales d'utilisation",
  52. 'label_attr'=> ["class"=>'checkbox-custom'],
  53. 'constraints' => [
  54. new IsTrue([
  55. 'message' => 'vous devez accepter notre charte.',
  56. ]),
  57. ],
  58. ])
  59. ->add('plainPassword', RepeatedType::class, [
  60. // instead of being set onto the object directly,
  61. // this is read and encoded in the controller
  62. 'mapped' => false,
  63. 'type' => PasswordType::class,
  64. 'invalid_message' => 'Les deux mots de passe doivent être identiques.',
  65. 'first_options' => ['label' => 'Mot de passe'],
  66. 'second_options' => ['label' => 'Répéter le mot de passe'],
  67. 'constraints' => [
  68. new NotBlank([
  69. 'message' => 'Entrez votre mot de passe',
  70. ]),
  71. new Length([
  72. 'min' => 3,
  73. 'minMessage' => 'Le mot de passe doit dépasser {{ limit }} caractères',
  74. // max length allowed by Symfony for security reasons
  75. 'max' => 4096,
  76. ]),
  77. ],
  78. ]);
  79. }
  80. public function configureOptions(OptionsResolver $resolver)
  81. {
  82. $resolver->setDefaults([
  83. 'data_class' => User::class,
  84. ]);
  85. }
  86. }