src/Form/Type/PrivateRegistrationStep2FormType.php line 22

Open in your IDE?
  1. <?php
  2. namespace App\Form\Type;
  3. use App\Entity\PrivateUser;
  4. use App\Parameter\ProviderInterface;
  5. use App\Twig\Extension\CountryExtension;
  6. use Symfony\Component\Form\AbstractType;
  7. use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
  8. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  9. use Symfony\Component\Form\Extension\Core\Type\CountryType;
  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\SubmitType;
  13. use Symfony\Component\Form\Extension\Core\Type\TextType;
  14. use Symfony\Component\Form\FormBuilderInterface;
  15. use Symfony\Component\OptionsResolver\OptionsResolver;
  16. use Symfony\Component\Validator\Constraints\Email;
  17. use Symfony\Component\Validator\Constraints\Length;
  18. use Symfony\Component\Validator\Constraints\NotBlank;
  19. class PrivateRegistrationStep2FormType extends AbstractType
  20. {
  21.     public function __construct(private readonly CountryExtension $countryExtension, private readonly ProviderInterface $provider)
  22.     {
  23.     }
  24.     public function buildForm(FormBuilderInterface $builder, array $options): void
  25.     {
  26.         $preferredCountry 'FR';
  27.         $visitorCountry $this->countryExtension->getVisitorCountry();
  28.         if ('' !== $visitorCountry) {
  29.             $preferredCountry strtoupper($visitorCountry);
  30.         }
  31.         $choices[''] = '';
  32.         foreach (explode(';', (string) $this->provider->getParameterValue('private.how_did_you_know')) as $value) {
  33.             $choices[$value] = $value;
  34.         }
  35.         $builder
  36.             ->add('lastname'TextType::class, [
  37.                 'label' => 'frontend.profile.form.type.label.lastname',
  38.                 'constraints' => [
  39.                     new NotBlank(),
  40.                 ],
  41.             ])
  42.             ->add('firstname'TextType::class, [
  43.                 'label' => 'frontend.profile.form.type.label.firstname',
  44.                 'constraints' => [
  45.                     new NotBlank(),
  46.                 ],
  47.             ])
  48.             ->add('email'EmailType::class, [
  49.                 'label' => 'frontend.profile.email',
  50.                 'constraints' => [
  51.                     new NotBlank(),
  52.                     new Email(),
  53.                 ],
  54.             ])
  55.             ->add('plainPassword'PasswordType::class, [
  56.                 'required' => true,
  57.                 'label' => 'frontend.profile.password',
  58.                 'attr' => ['placeholder' => 'frontend.page.register_pro.form.label.password'],
  59.                 'constraints' => [
  60.                     new Length([
  61.                         'min' => 8,
  62.                         'max' => 1024,
  63.                         'minMessage' => 'fos_user.password.short',
  64.                     ]),
  65.                     new NotBlank(),
  66.                 ],
  67.             ])
  68.             ->add('country'CountryType::class, [
  69.                 'label' => 'frontend.address.form.type.label.country',
  70.                 'placeholder' => '',
  71.                 'preferred_choices' => [$preferredCountry],
  72.                 'data' => $preferredCountry,
  73.                 'constraints' => [
  74.                     new NotBlank(),
  75.                 ],
  76.             ])
  77.             ->add('referralSource'ChoiceType::class, [
  78.                 'required' => false,
  79.                 'label' => 'frontend.address.form.type.label.referralSource',
  80.                 'choices' => $choices,
  81.                 'placeholder' => false,
  82.             ])
  83.             ->add('newsletter'CheckboxType::class, [
  84.                 'required' => false,
  85.                 'label' => 'frontend.registration.stay.informed',
  86.             ])
  87.             ->add('recaptcha'EWZRecaptchaCustomType::class)
  88.             ->add('submit'SubmitType::class, [
  89.                 'label' => 'Valider'// 'Valider' is a translation key
  90.                 'attr' => [
  91.                     'class' => 'btn06',
  92.                 ],
  93.             ])
  94.         ;
  95.     }
  96.     public function configureOptions(OptionsResolver $resolver): void
  97.     {
  98.         $resolver->setDefaults([
  99.             'locale' => null,
  100.             'data_class' => PrivateUser::class,
  101.             'validation_groups' => [
  102.                 'Default',
  103.                 'Registration',
  104.             ],
  105.         ]);
  106.     }
  107. }