<?php
namespace App\Form\Type;
use App\Dictionary\DictionaryMap;
use App\Entity\ProUser;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class ProRegistrationStep1FormType extends AbstractType
{
public function __construct(private readonly DictionaryMap $dictionaryMap)
{
}
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('company', TextType::class, [
'required' => true,
'label' => false,
'attr' => ['placeholder' => 'frontend.page.register_pro.form.label.company'],
])
->add('VAT', TextType::class, [
'required' => true,
'label' => false,
'attr' => ['placeholder' => 'frontend.page.register_pro.form.label.vat'],
])
->add('addressMaps', TextType::class, [
'required' => false,
'label' => false,
'mapped' => false,
'attr' => ['placeholder' => 'frontend.page.register_pro.form.label.search_address'],
])
->add('address', TextType::class, [
'required' => true,
'label' => false,
'attr' => ['placeholder' => 'frontend.page.register_pro.form.label.address'],
])
->add('zipCode', TextType::class, [
'required' => true,
'label' => false,
'attr' => ['placeholder' => 'frontend.page.register_pro.form.label.zipCode'],
])
->add('city', TextType::class, [
'required' => true,
'label' => false,
'attr' => ['placeholder' => 'frontend.page.register_pro.form.label.city'],
])
->add('country', ChoiceType::class, [
'required' => true,
'label' => false,
'choices' => $this->dictionaryMap->get('registration_form_country')->getValues(),
'preferred_choices' => [strtoupper((string) $options['locale'])],
'placeholder' => 'frontend.page.register_pro.form.label.country',
])
->add('siret', TextType::class, [
'required' => false,
'label' => false,
'attr' => ['placeholder' => 'frontend.page.register_pro.form.label.siret'],
])
->add('siren', TextType::class, [
'required' => false,
'label' => false,
'attr' => ['placeholder' => 'frontend.page.register_pro.form.label.siren'],
]);
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'locale' => null,
'data_class' => ProUser::class,
'validation_groups' => function (FormInterface $form) {
$data = $form->getData();
$groups = ['registration_pro_1'];
if (!$data->isForeigner()) {
$groups[] = 'france_specific';
}
return $groups;
},
]);
}
}