src/Form/RegistrationFormType.php line 27

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace App\Form;
  3. use App\Entity\User;
  4. use App\Utils\CommonConstants;
  5. use EWZ\Bundle\RecaptchaBundle\Form\Type\EWZRecaptchaType;
  6. use EWZ\Bundle\RecaptchaBundle\Validator\Constraints\IsTrue as RecaptchaTrue;
  7. use Symfony\Component\Form\AbstractType;
  8. use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
  9. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  10. use Symfony\Component\Form\Extension\Core\Type\EmailType;
  11. use Symfony\Component\Form\Extension\Core\Type\PasswordType;
  12. use Symfony\Component\Form\Extension\Core\Type\RepeatedType;
  13. use Symfony\Component\Form\Extension\Core\Type\TelType;
  14. use Symfony\Component\Form\Extension\Core\Type\TextType;
  15. use Symfony\Component\Form\FormBuilderInterface;
  16. use Symfony\Component\Form\FormEvent;
  17. use Symfony\Component\Form\FormEvents;
  18. use Symfony\Component\OptionsResolver\OptionsResolver;
  19. use Symfony\Component\Validator\Constraints\IsTrue;
  20. /**
  21.  * Class RegistrationFormType
  22.  * @package App\Form
  23.  */
  24. class RegistrationFormType extends AbstractType
  25. {
  26.     /**
  27.      * {@inheritdoc}
  28.      */
  29.     public function buildForm(FormBuilderInterface $builder, array $options)
  30.     {
  31.         $roles_array = [
  32.             CommonConstants::ROLE_MANDATARY => CommonConstants::ROLE_ROLE_MANDATARY,
  33.             CommonConstants::ROLE_DIRECTOR ' / ' CommonConstants::ROLE_ADVISOR => CommonConstants::ROLE_ROLE_DIRECTOR,
  34.             CommonConstants::ROLE_COACH => CommonConstants::ROLE_ROLE_COACH
  35.         ];
  36.         $builder
  37.             ->add('email'EmailType::class, [
  38.                 "label" => "Email ",
  39.                 "label_attr" => ["class" => "label-weact col-12"'style'=>"text-align:start"],
  40.                 "attr" => ["class" => "form-control form-control-sm border-weact",
  41.                     "id" => "inputEmail",
  42.                     "placeholder" => "Email de connexion"
  43.                 ]
  44.             ])
  45.             ->add('agreeTerms'CheckboxType::class, [
  46.                 'mapped' => false,
  47.                 "label" => "En cochant la case vous acceptez les CGU",
  48.                 "label_attr" => ["class" => "label-weact "'style'=>"text-align:start"],
  49.                 'constraints' => [
  50.                     new IsTrue([
  51.                         'message' => 'Vous devez accepter nos conditions',
  52.                     ])
  53.                 ]
  54.             ])
  55.             ->add('password'RepeatedType::class, [
  56.                 'type' => PasswordType::class,
  57.                 'invalid_message' => 'Vos Mots de passe doivent correspondre',
  58.                 'required' => true,
  59.                 'first_options' => ["label_attr" => ["class" => "label-weact col-12 control-label"'style'=>"text-align:start"],
  60.                     "label" => "Mot de passe ",
  61.                     "attr" => ["class" => "form-control form-control-sm border-weact",
  62.                         "placeholder" => "Saisissez votre mot de passe"]
  63.                 ],
  64.                 'second_options' => [
  65.                     "label" => "Confirmez le mot de passe",
  66.                     "attr" => [
  67.                         "class" => "form-control form-control-sm border-weact",
  68.                         "placeholder" => "Confirmez votre mot de passe"],
  69.                     'mapped' => true
  70.                 ],
  71.             ])
  72.             ->add('civility'ChoiceType::class, [
  73.                 "placeholder" => "Civilité",
  74.                 'choices' => [
  75.                     "M." => "M.",
  76.                     "Mme" => "Mme"
  77.                 ],
  78.                 "attr" => [
  79.                     "class" => "form-control form-control-sm border-weact"
  80.                 ],
  81.                 'label' => 'Civilité ',
  82.                 "label_attr" => ["class" => "label-weact col-12"'style'=>"text-align:start"],
  83.             ])
  84.             ->add('lastName'TextType::class, [
  85.                 'label' => 'Votre nom ',
  86.                 "label_attr" => ["class" => "label-weact col-12"'style'=>"text-align:start"],
  87.                 "attr" => ["class" => "form-control form-control-sm border-weact"'placeholder' => 'Votre nom']
  88.             ])
  89.             ->add('firstName'TextType::class, [
  90.                 'label' => 'Votre prénom ',
  91.                 "label_attr" => ["class" => "label-weact col-12"'style'=>"text-align:start"],
  92.                 "attr" => ["class" => "form-control form-control-sm border-weact"'placeholder' => 'Votre prénom']
  93.             ])
  94.             ->add('nomEtablissement'TextType::class, [
  95.                 'label' => 'Nom de votre établissement ',
  96.                 "label_attr" => ["class" => "label-weact col-12"'style'=>"text-align:start"],
  97.                 "mapped"=>false,
  98.                 'required'=>false,
  99.                 "attr" => ["class" => "form-control form-control-sm border-weact"'placeholder' => 'Nom de votre établissement']
  100.             ])
  101.             ->add('phoneMobilePro'TelType::class, [
  102.                 'label' => 'Téléphone portable ',
  103.                 "label_attr" => ["class" => "label-weact col-12"'style'=>"text-align:start"],
  104.                 "attr" => ["class" => "form-control form-control-sm border-weact"'placeholder' => 'Téléphone mobile']
  105.             ])
  106.             ->add('address'TextType::class, [
  107.                 'label' => 'Adresse ',
  108.                 "label_attr" => ["class" => "label-weact col-12"'style'=>"text-align:start"],
  109.                 "attr" => ["class" => "form-control form-control-sm border-weact"'placeholder' => 'Votre adresse']
  110.             ])
  111.             ->add('addressComplement'TextType::class, [
  112.                 "required" => false,
  113.                 "label" => "Complement d'adresse",
  114.                 "label_attr" => ["class" => "label-weact col-12"'style'=>"text-align:start"],
  115.                 "attr" => ["class" => "form-control form-control-sm border-weact"'placeholder' => 'Complément d\'adresse']
  116.             ])
  117.             ->add('zipCode'TextType::class, [
  118.                 "label" => "Code postal ",
  119.                 "label_attr" => ["class" => "label-weact col-12"'style'=>"text-align:start"],
  120.                 "attr" => ["class" => "form-control form-control-sm border-weact"'placeholder' => 'CP']
  121.             ])
  122.             ->add('city'TextType::class, [
  123.                 "label" => "Ville ",
  124.                 "label_attr" => ["class" => "label-weact col-12"'style'=>"text-align:start"],
  125.                 "attr" => ["class" => "form-control form-control-sm border-weact"'placeholder' => 'Ville']
  126.             ])
  127.             ->add('roles'ChoiceType::class, [
  128.                 'mapped' => false,
  129.                 "placeholder" => "Type de conseiller",
  130.                 "label_attr" => ["class" => "label-weact col-12"'style'=>"text-align:start"],
  131.                 'choices' => $roles_array,
  132.                 "attr" => [
  133.                     "class" => "form-control form-control-sm "
  134.                 ]
  135.             ]);
  136.         $builder->add('recaptcha'EWZRecaptchaType::class, [
  137.             'mapped' => false,
  138.             'constraints' => [new RecaptchaTrue()],
  139.             'attr' => [
  140.                 'options' => [
  141.                     'theme' => 'light',
  142.                     'type' => 'image',
  143.                     'size' => 'normal',
  144.                     'defer' => true,
  145.                     'async' => true
  146.                 ]
  147.             ]]);
  148.         $builder->addEventListener(FormEvents::PRE_SUBMIT, function (FormEvent $event) {
  149.             /** @var User $user */
  150.             $user $event->getForm()->getData();
  151.             $data $event->getData();
  152.             $roles = [$data['roles']];
  153.             if ($data['roles'] === CommonConstants::ROLE_ROLE_DIRECTOR) {
  154.                 $roles[] = CommonConstants::ROLE_ROLE_ADVISOR;
  155.             }
  156.             $user->addRoles($roles);
  157.         });
  158.     }
  159.     /**
  160.      * {@inheritdoc}
  161.      */
  162.     public function configureOptions(OptionsResolver $resolver)
  163.     {
  164.         $resolver->setDefaults([
  165.             'data_class' => User::class,
  166.             'allow_extra_fields' => true
  167.         ]);
  168.     }
  169. }