<?php
declare (strict_types = 1);
/*
* Copyright (C) Office National de Publication et de Communication - All Rights Reserved
*
* Unauthorized copying of this file, via any medium is strictly prohibited by law
* This file is proprietary and confidential
*/
namespace App\Form;
use App\Entity\DemandeInformation;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Validator\Constraints\Email;
use Symfony\Component\Validator\Constraints\Regex;
use Symfony\Component\Validator\Constraints\Length;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\TelType;
use Symfony\Component\Validator\Constraints\NotEqualTo;
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\TextareaType;
final class DemandeInformationType extends AbstractType
{
/** @var array */
private const PROFILS = [
'Parent' => 'Parent',
'Elève' => 'Elève',
'Etudiant(e)' => 'Etudiant',
'Conseiller(e) d\'orientation' => 'Conseiller d\'orientation',
'Chef d\'établissement' => 'Chef d\'établissement',
];
/** @var array */
private const NIVEAUX = [
'Maternelle' => 'Maternelle',
'Primaire' => 'Primaire',
'Collège' => 'Collège',
'Lycée' => 'Lycée',
'Professionnel' => 'Professionnel',
'Post-Bac' => 'Post-Bac',
];
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('profil', ChoiceType::class, [
'choices' => self::PROFILS,
])
->add('niveau', ChoiceType::class, [
'multiple' => true,
'expanded' => true,
'choices' => self::NIVEAUX,
])
->add('interlocuteurPrenom', null, [
'required' => true,
'constraints' => [new Length(['min' => 3, 'max' => 30])],
])
->add('interlocuteurNom', null, [
'required' => true,
'constraints' => [new Length(['min' => 3, 'max' => 30])],
'attr' => ['maxlength' => 30],
])
->add('adresse', null, ['constraints' => [new Length(['max' => 100])]])
->add('cp', null, ['constraints' => [new Length(['max' => 7])]])
->add('ville', null, ['constraints' => [new Length(['max' => 30])]])
->add('interlocuteurTelephone', TelType::class, [
'attr' => [
'pattern' => '.*(?<!760463968)$',
'title' => 'Le numéro de téléphone est bloqué !',
'maxlength' => 30,
],
'help' => 'Numéro réservé au rappel par l’établissement',
'help_attr' => ['class' => 'help-telephone']
])
->add('interlocuteurEmail', EmailType::class, [
'required' => true,
'constraints' => [
new Email(),
new Regex([
'pattern' => '/^(?!Delebarrenicolas|nicolasdelebarre)[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/i',
'message' => 'Cette adresse email est interdite.'
]),
],
'attr' => ['maxlength' => 35],
])
->add('commentaires', TextareaType::class,
[
'required' => true,
'constraints' => [new Length(['max' => 500])],
'data' => 'Je souhaite recevoir des informations sur cet établissement...',
'attr' => [
'maxlength' => 500,
],
])
->add('autoriseContact', null, ['required' => false])
/* Honeypot : */
->add('email2', TextType::class,
[
'required' => false,
'mapped' => false,
'label' => false,
'attr' => [
'style' => 'display:none !important',
'tabindex' => '-1',
'autocomplete' => 'off',
],
]);
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => DemandeInformation::class,
]);
}
}