src/Form/Type/ProRegistrationStep1FormType.php line 78

Open in your IDE?
  1. <?php
  2. namespace App\Form\Type;
  3. use App\Dictionary\DictionaryMap;
  4. use App\Entity\ProUser;
  5. use Symfony\Component\Form\AbstractType;
  6. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  7. use Symfony\Component\Form\Extension\Core\Type\TextType;
  8. use Symfony\Component\Form\FormBuilderInterface;
  9. use Symfony\Component\Form\FormInterface;
  10. use Symfony\Component\OptionsResolver\OptionsResolver;
  11. class ProRegistrationStep1FormType extends AbstractType
  12. {
  13.     public function __construct(private readonly DictionaryMap $dictionaryMap)
  14.     {
  15.     }
  16.     public function buildForm(FormBuilderInterface $builder, array $options): void
  17.     {
  18.         $builder
  19.             ->add('company'TextType::class, [
  20.                 'required' => true,
  21.                 'label' => false,
  22.                 'attr' => ['placeholder' => 'frontend.page.register_pro.form.label.company'],
  23.             ])
  24.             ->add('VAT'TextType::class, [
  25.                 'required' => true,
  26.                 'label' => false,
  27.                 'attr' => ['placeholder' => 'frontend.page.register_pro.form.label.vat'],
  28.             ])
  29.             ->add('addressMaps'TextType::class, [
  30.                 'required' => false,
  31.                 'label' => false,
  32.                 'mapped' => false,
  33.                 'attr' => ['placeholder' => 'frontend.page.register_pro.form.label.search_address'],
  34.             ])
  35.             ->add('address'TextType::class, [
  36.                 'required' => true,
  37.                 'label' => false,
  38.                 'attr' => ['placeholder' => 'frontend.page.register_pro.form.label.address'],
  39.             ])
  40.             ->add('zipCode'TextType::class, [
  41.                 'required' => true,
  42.                 'label' => false,
  43.                 'attr' => ['placeholder' => 'frontend.page.register_pro.form.label.zipCode'],
  44.             ])
  45.             ->add('city'TextType::class, [
  46.                 'required' => true,
  47.                 'label' => false,
  48.                 'attr' => ['placeholder' => 'frontend.page.register_pro.form.label.city'],
  49.             ])
  50.             ->add('country'ChoiceType::class, [
  51.                 'required' => true,
  52.                 'label' => false,
  53.                 'choices' => $this->dictionaryMap->get('registration_form_country')->getValues(),
  54.                 'preferred_choices' => [strtoupper((string) $options['locale'])],
  55.                 'placeholder' => 'frontend.page.register_pro.form.label.country',
  56.             ])
  57.             ->add('siret'TextType::class, [
  58.                 'required' => false,
  59.                 'label' => false,
  60.                 'attr' => ['placeholder' => 'frontend.page.register_pro.form.label.siret'],
  61.             ])
  62.             ->add('siren'TextType::class, [
  63.                 'required' => false,
  64.                 'label' => false,
  65.                 'attr' => ['placeholder' => 'frontend.page.register_pro.form.label.siren'],
  66.             ]);
  67.     }
  68.     public function configureOptions(OptionsResolver $resolver): void
  69.     {
  70.         $resolver->setDefaults([
  71.             'locale' => null,
  72.             'data_class' => ProUser::class,
  73.             'validation_groups' => function (FormInterface $form) {
  74.                 $data $form->getData();
  75.                 $groups = ['registration_pro_1'];
  76.                 if (!$data->isForeigner()) {
  77.                     $groups[] = 'france_specific';
  78.                 }
  79.                 return $groups;
  80.             },
  81.         ]);
  82.     }
  83. }