<?php
namespace App\Form;
use App\Entity\TypeAdherent;
use App\Entity\User;
use Doctrine\ORM\EntityRepository;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
use Symfony\Component\Form\Extension\Core\Type\RepeatedType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\TelType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Validator\Constraints\IsTrue;
use Symfony\Component\Validator\Constraints\Length;
use Symfony\Component\Validator\Constraints\NotBlank;
class RegistrationFormType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('societe', TextType::class, [
'trim' => true,
'label' => 'Raison sociale* : ',
])
->add('typeAdherent', EntityType::class, [
'trim' => true,
'label' => 'Vous représentez* : ',
'required' => true,
'class' => TypeAdherent::class,
'query_builder' => function (EntityRepository $er) {
return $er->createQueryBuilder('typeAdherent')
//retrait du type administateur de la liste
->where('typeAdherent.niveau > 1')
->orderBy('typeAdherent.niveau', 'ASC');
},
'choice_label' => 'intitule',
])
->add('adresse', AdressFormType::class)
->add('prenom', TextType::class, [
'trim' => true,
'label' => 'Prénom* : ',
'attr' => array('placeholder' => 'Insérez le prénom'),
])
->add('nom', TextType::class, [
'trim' => true,
'label' => 'Nom* : ',
'attr' => array('placeholder' => 'Insérez le nom'),
])
->add('profession', TextType::class, [
'trim' => true,
'label' => 'Fonction* : ',
])
->add('telephone', TextType::class, [
'trim' => true,
'label' => 'Téléphone* : ',
'attr' => array('placeholder' => 'Insérez le téléphone'),
])
->add('fax', TextType::class, [
'trim' => true,
'label' => 'Fax* : ',
'attr' => array('placeholder' => 'Insérez un numéro de fax'),
])
->add('telephonePortable', TextType::class, [
'trim' => true,
'label' => 'Portable : ',
'required' => false,
])
->add('email', TextType::class, [
'trim' => true,
'label' => 'Email* : ',
'attr' => array('placeholder' => 'Insérez l\'adresse mail'),
])
//----------------------------------------------------------------------------------------
->add('password', RepeatedType::class, array(
'type' => PasswordType::class,
'required' => true,
'invalid_message' => 'Les champs de mot de passe ne sont pas identiques!',
'first_options' => array('label' => 'Mot de passe* : '),
'second_options' => array('label' => 'Confirmez le mot de passe* : '),
))
->add('agreeTerm', CheckboxType::class, [
'label' => 'Vous acceptez les conditions d\'utilisation',
'mapped' => false,
'constraints' => [
new IsTrue([
'message' => 'Vous devez accepter les conditions d\'utilisation',
]),
],
])
->add('Enregistrer', SubmitType::class, [
'label' => 'Enregistrer'
]);
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => User::class,
]);
}
}