<?php
namespace App\Form;
use App\Entity\User;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
use Symfony\Component\Form\Extension\Core\Type\RepeatedType;
use Symfony\Component\Validator\Constraints\Email;
use Symfony\Component\Validator\Constraints\Length;
use Symfony\Component\Validator\Constraints\NotBlank;
use App\Validator\Constraints\UniqueEmail;
class UserTransporteurType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('civility', ChoiceType::class, [
'label' => 'Civilité',
'choices' => [
'M.' => 'Monsieur',
'Mme' => 'Madame',
'Je ne préfère pas le dire' => 'Inconnu'
],
'attr' => [
'class' => 'chosen-select no-search-select nice-select-civility mb-0'
],
'placeholder' => '-Choisir votre civilité-',
'required' => true
])
->add('lastname', TextType::class, [
'label' => '<i class="far fa-user"></i> Nom',
'label_html' => true,
'attr' => [
'maxlength' => 60
],
'constraints' => [
new Length([
'min' => 3,
'minMessage' => 'Le nom doit avoir au moins {{ limit }} caractères.',
]),
new NotBlank([
'message' => 'Veuillez entrer votre nom !',
]),
],
'required' => true
])
->add('firstname', TextType::class, [
'label' => 'Prénom <i class="far fa-user"></i>',
'label_html' => true,
'attr' => [
'maxlength' => 60
],
'constraints' => [
new Length([
'min' => 3,
'minMessage' => 'Le prénom doit avoir au moins {{ limit }} caractères.',
]),
new NotBlank([
'message' => 'Veuillez entrer prénom !',
]),
],
'required' => true
])
->add('email', EmailType::class, [
'label' => 'Adresse email professionnel <i class="far fa-envelope"></i>',
'label_html' => true,
'attr' => [
'maxlength' => 180
],
'constraints' => [
new NotBlank([
'message' => 'Veuillez entrer votre email !',
]),
new Email([
'message' => 'L\'adresse email "{{ value }}" n\'est pas valide.',
]),
new UniqueEmail([
'message' => 'Cet e-mail est déjà utilisé par un autre compte.',
])
],
'required' => true
])
->add('password', RepeatedType::class, [
'mapped' => false,
'attr' => [
'minlength' => 8
],
'constraints' => [
new Length([
'min' => 8,
'minMessage' => 'Le mot de passe doit avoir au moins {{ limit }} caractères.',
]),
new NotBlank([
'message' => 'Veuillez entrer votre mot de passe !',
]),
],
'type' => PasswordType::class,
'invalid_message' => 'Le deux mots de passe ne sont pas identiques !',
'options' => [
'attr' => [
'maxlength' => 255,
'autocomplete' => 'off',
]
],
'required' => true,
'first_options' => [
'label' => '<i class="fas fa-lock"></i> Mot de passe',
'label_html' => true,
'attr' => [
'placeholder' => 'Mot de passe',
]
],
'second_options' => [
'label' => '<i class="fas fa-lock"></i> Confirmer le mot de passe',
'label_html' => true,
'attr' => [
'placeholder' => 'Confirmer le mot de passe'
]
]
])
;
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => User::class,
]);
}
}