src/Form/AccountProRegistrationType.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Form;
  3. use Symfony\Component\Form\AbstractType;
  4. use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
  5. use Symfony\Component\Form\Extension\Core\Type\EmailType;
  6. use Symfony\Component\Form\Extension\Core\Type\TextType;
  7. use Symfony\Component\Form\FormBuilderInterface;
  8. use Symfony\Component\Routing\RouterInterface;
  9. use Symfony\Component\Validator\Constraints\Email;
  10. use Symfony\Component\Validator\Constraints\NotBlank;
  11. class AccountProRegistrationType extends AbstractType
  12. {
  13.     private RouterInterface $router;
  14.     public function __construct(RouterInterface $router)
  15.     {
  16.         $this->router $router;
  17.     }
  18.     /**
  19.      * Permet de générer des placeholders avec des prénoms aléatoires aussi bien masculin que féminin
  20.      */
  21.     private array $placeholders = [
  22.         [
  23.             'email'     => 'valentine@gmail.com',
  24.             'firstname' => 'Valentine',
  25.             'name'      => 'Dupond',
  26.         ],
  27.         [
  28.             'email'     => 'charlie@gmail.com',
  29.             'firstname' => 'Charlie',
  30.             'name'      => 'Dupond',
  31.         ],
  32.         [
  33.             'email'     => 'alice@gmail.com',
  34.             'firstname' => 'Alice',
  35.             'name'      => 'Dupond',
  36.         ]
  37.     ];
  38.     public function buildForm(FormBuilderInterface $builder, array $options)
  39.     {
  40.         $placeholder $this->getRandomPlaceholder();
  41.         $cguLink $this->router->generate("cgu");
  42.         $builder
  43.             ->add(
  44.                 'rpps',
  45.                 TextType::class,
  46.                 [
  47.                     'label'       => 'Identifiant RPPS / ADELI',
  48.                     'required'    => true,
  49.                     'attr'        => [
  50.                         'placeholder' => 'Ex : 010000000'
  51.                     ],
  52.                     'constraints' => [
  53.                         new NotBlank(['message' => "Le numéro RPPS est obligatoire"]),
  54.                     ],
  55.                 ]
  56.             )
  57.             ->add(
  58.                 'email',
  59.                 EmailType::class,
  60.                 [
  61.                     'label'       => 'Adresse email',
  62.                     'required'    => true,
  63.                     'attr'        => [
  64.                         'placeholder' => 'Ex : ' $placeholder['email'],
  65.                         'pattern'     => '[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,4}$'
  66.                     ],
  67.                     'constraints' => [
  68.                         new NotBlank(['message' => "L'adresse email est obligatoire"]),
  69.                         new Email()
  70.                     ],
  71.                 ]
  72.             )
  73.             ->add(
  74.                 'firstname',
  75.                 TextType::class,
  76.                 [
  77.                     'label'       => 'Prénom',
  78.                     'required'    => true,
  79.                     'attr'        => [
  80.                         'placeholder' => 'Ex : ' $placeholder['firstname']
  81.                     ],
  82.                     'constraints' => [
  83.                         new NotBlank(['message' => "Le prénom est obligatoire"]),
  84.                     ],
  85.                 ]
  86.             )
  87.             ->add(
  88.                 'lastname',
  89.                 TextType::class,
  90.                 [
  91.                     'label'       => 'Nom',
  92.                     'required'    => true,
  93.                     'attr'        => [
  94.                         'placeholder' => 'Ex : ' $placeholder['name']
  95.                     ],
  96.                     'constraints' => [
  97.                         new NotBlank(['message' => "Le nom est obligatoire"]),
  98.                     ],
  99.                 ]
  100.             )
  101.             ->add(
  102.                 'profession',
  103.                 TextType::class,
  104.                 [
  105.                     'label'       => 'Profession',
  106.                     'required'    => true,
  107.                     'attr'        => [
  108.                         'placeholder' => 'Ex : kinésithérapeute, médecin, ...'
  109.                     ],
  110.                     'constraints' => [
  111.                         new NotBlank(['message' => "La profession est obligatoire"]),
  112.                     ],
  113.                 ]
  114.             )
  115.             ->add(
  116.                 'mobile',
  117.                 TextType::class,
  118.                 [
  119.                     'label'       => 'Numéro de mobile (facultatif)',
  120.                     'required'    => false,
  121.                     'attr'        => [
  122.                         'placeholder' => 'Ex : 07.01.02.03.04'
  123.                     ],
  124.                 ]
  125.             )
  126.             ->add(
  127.                 'cgu',
  128.                 CheckboxType::class,
  129.                 [
  130.                     'label' => "J'accepte les <a href=\"$cguLink\" target='_blank' class=\"a\">CGU</a>",
  131.                     'label_html' => true,
  132.                     'required' => true,
  133.                     'constraints' => [
  134.                         new NotBlank(['message' => "Vous devez accepter les CGU"]),
  135.                     ],
  136.                 ]
  137.             );
  138.     }
  139.     /**
  140.      * Retourne aléatoirement un utilisateur placeholder
  141.      */
  142.     private function getRandomPlaceholder(): array
  143.     {
  144.         \shuffle($this->placeholders);
  145.         return \current($this->placeholders);
  146.     }
  147. }