<?php
namespace App\Form;
use App\Entity\{Transporteur, Department, Country, ProfessionalType};
use App\Form\UserTransporteurType;
use App\Repository\{DepartmentRepository, CountryRepository};
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\TelType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\DateType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\FileType;
use Symfony\Component\Validator\Constraints\Email;
use Symfony\Component\Validator\Constraints\IsTrue;
use Symfony\Component\Validator\Constraints\Length;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Validator\Constraints\Count;
use App\Validator\Constraints\UniqueEmail;
use App\Validator\Constraints\ValidPhoneNumber;
use Symfony\Component\Validator\Constraints\Regex;
use Symfony\Component\Routing\RouterInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
class TransporteurType extends AbstractType
{
private $router;
private $translator;
public function __construct(RouterInterface $router, TranslatorInterface $translator)
{
$this->router = $router;
$this->translator = $translator;
}
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$termsUrl = $this->router->generate('app_front_terms');
$privacyUrl = $this->router->generate('app_front_privacy');
$builder
->add('professionalType', EntityType::class, [
'label' => 'Type de professionnel',
'label_attr' => [
'class' => 'width-auto mt-08rem'
],
'attr' => [
'class' => 'chosen-select search-select nice-select-profession mb-0'
],
'class' => ProfessionalType::class,
'choice_label' => 'name',
'multiple' => true,
'expanded' => false,
'required' => true,
'constraints' => [
new NotBlank([
'message' => 'Veuillez entrer votre type de professionnel !',
])
]
])
->add('socialDenomination', TextType::class, [
'label' => '<i class="fas fa-building"></i> Dénomination sociale',
'label_html' => true,
'constraints' => [
new NotBlank([
'message' => 'Veuillez entrer votre dénomination sociale !',
]),
],
'required' => true
])
->add('siret', TextType::class, [
'label' => '<i class="fas fa-id-card"></i> Numéro Siret ou Siren',
'label_html' => true,
'attr' => [
'maxlength' => '14',
'minlength' => '9'
],
'constraints' => [
new Length([
'min' => 9,
'max' => 14,
'minMessage' => 'Le Numéro Siret ou Siren doit avoir au moins {{ limit }} caractères.',
'maxMessage' => 'Le numéro SIRET ou SIREN ne peut pas contenir plus de {{ limit }} caractères.',
]),
new NotBlank([
'message' => 'Veuillez entrer votre numéro SIRET ou SIREN !',
]),
],
'required' => true
])
->add('tva', TextType::class, [
'label' => '<i class="fas fa-receipt"></i> TVA',
'label_html' => true,
'required' => false
])
->add('landlinePhone', TelType::class, [
'label' => 'Téléphone professionnel <i class="far fa-phone-office"></i>',
'label_html' => true,
'attr' => [
'maxlength' => 20
],
'constraints' => [
new ValidPhoneNumber(),
new Length([
'min' => 8,
'minMessage' => 'Le numéro de téléphone fixe doit avoir au moins {{ limit }} caractères.',
])
],
'required' => false
])
->add('address', TextType::class, [
'label' => 'Adresse <i class="fas fa-map-marker"></i>',
'label_html' => true,
'constraints' => [
new NotBlank([
'message' => 'Veuillez entrer votre adresse !',
]),
new Length([
'min' => 3,
'minMessage' => 'L\'adresse doit avoir au moins {{ limit }} caractères.',
]),
],
'attr' => [
'placeholder' => 'Choisissez votre adresse',
'autocomplete' => 'off',
'class' => 'autocomplete-input-transporteur'
],
'required' => true
])
->add('address1', TextType::class, [
'label' => 'Adresse 2 <i class="fas fa-map-marker"></i>',
'label_html' => true,
'constraints' => [
new Length([
'min' => 3,
'minMessage' => 'L\'adresse 2 doit avoir au moins {{ limit }} caractères.',
]),
],
'attr' => [
'placeholder' => 'Complément d\'adresse',
'minlength' => 3,
'autocomplete' => 'off'
],
'required' => false
])
->add('postalCode', TextType::class, [
'label' => 'Code postal <i class="fas fas fa-map-pin"></i>',
'label_html' => true,
'constraints' => [
new NotBlank([
'message' => 'Veuillez entrer votre code postal !',
]),
new Regex([
'pattern' => '/^\d+$/',
'message' => 'Le code postal doit contenir uniquement des chiffres.',
]),
new Length([
'min' => 3,
'minMessage' => 'Le code postal doit avoir au moins {{ limit }} chiffres.',
]),
],
'attr' => [
'minlength' => 3
],
'required' => true
])
->add('city', TextType::class, [
'label' => 'Ville <i class="fas fa-city"></i>',
'label_html' => true,
'constraints' => [
new NotBlank([
'message' => 'Veuillez entrer votre ville !',
]),
new Length([
'min' => 3,
'minMessage' => 'La ville doit avoir au moins {{ limit }} caractères.',
]),
],
'attr' => [
'minlength' => 3,
],
'required' => true
])
->add('department', EntityType::class, [
'label' => 'Département de travail principal',
'attr' => [
'class' => 'chosen-select search-select nice-select-map mb-0'
],
'class' => Department::class,
'choice_label' => 'name',
'query_builder' => function (DepartmentRepository $repo) {
return $repo->createQueryBuilder('d')
->where('d.status = :status')
->setParameter('status', true);
},
'constraints' => [
new NotBlank([
'message' => 'Veuillez entrer votre département !',
])
],
'required' => true
])
->add('country', EntityType::class, [
'label' => 'Pays',
'attr' => [
'class' => 'chosen-select search-select nice-select-country mb-0'
],
'class' => Country::class,
'choice_label' => function (Country $country) {
return $country->getPays();
},
'query_builder' => function (CountryRepository $repo) {
return $repo->createQueryBuilder('c')
->where('c.status = :status')
->setParameter('status', true);
},
'constraints' => [
new NotBlank([
'message' => 'Veuillez entrer votre pays !',
]),
],
'required' => true,
])
->add('longitude', TextType::class, [
'label' => 'Longitude <i class="fal fa-long-arrow-alt-right"></i>',
'label_html' => true,
'label_attr' => [
'class' => 'width-auto mt-08rem'
],
'constraints' => [
new NotBlank([
'message' => 'Veuillez entrer votre longitude !',
]),
],
'attr' => [
'placeholder' => 'Map Longitude'
],
'required' => true
])
->add('latitude', TextType::class, [
'label' => 'Latitude <i class="fal fa-long-arrow-alt-right"></i>',
'label_html' => true,
'label_attr' => [
'class' => 'width-auto mt-08rem'
],
'constraints' => [
new NotBlank([
'message' => 'Veuillez entrer votre latitude !',
]),
],
'attr' => [
'placeholder' => 'Map Latitude'
],
'required' => true
])
->add('typePersonne', ChoiceType::class, [
'label' => 'J\'interviens en tant que',
'choices' => [
'Dirigeant de l\'entreprise' => 'Dirigeant de l\'entreprise',
'Responsable' => 'Responsable',
'Secrétaire' => 'Secrétaire',
'Autre' => 'Autre',
],
'expanded' => true,
'multiple' => false,
'required' => true
// 'data' => 'Dirigeant de l\'entreprise'
])
->add('otherFunction', TextType::class, [
'label' => 'Précisez votre profession (si autre)',
'required' => false,
])
->add('user', UserTransporteurType::class, [
'label' => true
])
->add('birthday', DateType::class, [
'label' => 'Date de naissance <i class="fas fa-calendar-alt"></i>',
'label_html' => true,
'widget' => 'single_text',
'constraints' => [
new NotBlank([
'message' => 'Veuillez entrer votre date de naissance !',
])
],
'html5' => false,
'format' => 'dd-MM-yyyy',
'attr' => [
'class' => 'flatpickr-birthday',
'placeholder' => 'jj-mm-aaaa',
'readonly' => true
],
'required' => true
])
->add('birthplace', TextType::class, [
'label' => 'Lieu de naissance <i class="fas fa-map-marker-alt"></i>',
'label_html' => true,
'constraints' => [
new NotBlank([
'message' => 'Veuillez entrer votre lieu de naissance !',
]),
],
'required' => true
])
->add('mobilePhone', TelType::class, [
'label' => 'Téléphone personnel <i class="far fa-phone"></i>',
'label_html' => true,
'attr' => [
'maxlength' => 20
],
'constraints' => [
new NotBlank([
'message' => 'Veuillez entrer votre numéro de téléphone !',
]),
new ValidPhoneNumber(),
new Length([
'min' => 10,
'minMessage' => 'Le numéro de téléphone mobile doit avoir au moins {{ limit }} caractères.',
])
],
'required' => true
])
->add('agreeTerms', CheckboxType::class, [
'mapped' => false,
'constraints' => [
new IsTrue([
'message' => 'Vous devez accepter notre conditions.',
]),
],
'label_attr' => [
'style' => 'width: 90% !important; margin-left: 0.5rem; cursor: pointer !important'
],
'label' => sprintf(
'J\'accepte les <a href="%s" class="text-theme-blue">%s</a> et la <a href="%s" class="text-theme-blue">%s</a>.',
$termsUrl,
$this->translator->trans('conditions d\'utilisation'),
$privacyUrl,
$this->translator->trans('politique de confidentialité')
),
'label_html' => true,
'required' => true
])
;
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => Transporteur::class,
]);
}
/**
* {@inheritdoc}
*/
public function getBlockPrefix()
{
return 'sg_transporteur';
}
}