src/Form/ContactType.php line 16

Open in your IDE?
  1. <?php
  2. namespace App\Form;
  3. use App\Entity\Contact;
  4. use App\Repository\ContactRepository;
  5. use Symfony\Component\Form\AbstractType;
  6. use Symfony\Component\Form\FormBuilderInterface;
  7. use Symfony\Component\Validator\Constraints\NotBlank;
  8. use Symfony\Component\OptionsResolver\OptionsResolver;
  9. use Symfony\Component\Form\Extension\Core\Type\TextType;
  10. use Symfony\Component\Form\Extension\Core\Type\EmailType;
  11. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  12. use Symfony\Component\Form\Extension\Core\Type\TextareaType;
  13. class ContactType extends AbstractType
  14. {
  15.     protected $contactRepository;
  16.     protected $project;
  17.     public function __construct(ContactRepository $contactRepository$project)
  18.     {
  19.         $this->contactRepository $contactRepository;
  20.         $this->project $project;
  21.     }
  22.     public function buildForm(FormBuilderInterface $builder, array $options): void
  23.     {
  24.         $builder
  25.             ->add('lastname'TextType::class, [
  26.                 'label' => false,
  27.                 'attr' => [
  28.                     'class' => 'form-control form-control-lg',
  29.                     'placeholder' => 'Contact.input.lastname.placeholder'
  30.                 ],
  31.                 'row_attr' => ['class' => 'col-xl-6'],
  32.                 'required' => false,
  33.                 'constraints' => [
  34.                     new NotBlank(['message' => 'notBlank'])
  35.                 ]
  36.             ])
  37.             ->add('firstname'TextType::class, [
  38.                 'label' => false,
  39.                 'attr' => [
  40.                     'class' => 'form-control form-control-lg',
  41.                     'placeholder' => 'Contact.input.firstname.placeholder'
  42.                 ],
  43.                 'row_attr' => ['class' => 'col-xl-6'],
  44.                 'required' => false,
  45.                 'constraints' => [
  46.                     new NotBlank(['message' => 'notBlank'])
  47.                 ]
  48.             ])
  49.             ->add('email'EmailType::class, [
  50.                 'label' => false,
  51.                 'attr' => [
  52.                     'class' => 'form-control form-control-lg',
  53.                     'placeholder' => 'Contact.input.email.placeholder'
  54.                 ],
  55.                 'row_attr' => ['class' => 'col-xl-6'],
  56.                 'required' => false,
  57.                 'constraints' => [
  58.                     new NotBlank(['message' => 'notBlank'])
  59.                 ]
  60.             ])
  61.             ->add('phone'TextType::class, [
  62.                 'label' => false,
  63.                 'attr' => [
  64.                     'class' => 'form-control form-control-lg',
  65.                     'placeholder' => 'Contact.input.phone.placeholder'
  66.                 ],
  67.                 'row_attr' => ['class' => 'col-xl-6'],
  68.                 'required' => false,
  69.                 'constraints' => [
  70.                     new NotBlank(['message' => 'notBlank'])
  71.                 ]
  72.             ]);
  73.         if ($this->project != 'CONFERENCE') {
  74.             $builder
  75.                 ->add('service'ChoiceType::class, [
  76.                     'label' => false,
  77.                     'attr' => [
  78.                         'class' => 'form-select form-control-lg'
  79.                     ],
  80.                     'placeholder' => 'Contact.input.service.placeholder',
  81.                     'choices' => $this->contactRepository->getServices($this->project),
  82.                     'required' => false,
  83.                     'row_attr' => ['class' => 'col-xl-12'],
  84.                     'constraints' => [
  85.                         new NotBlank(['message' => 'notBlank'])
  86.                     ]
  87.                 ]);
  88.         }
  89.         $builder
  90.             ->add('message'TextareaType::class, [
  91.                 'label' => false,
  92.                 'attr' => ['placeholder' => 'Contact.input.message.placeholder'],
  93.                 'row_attr' => ['class' => 'col-xl-12'],
  94.                 'required' => false,
  95.                 'constraints' => [
  96.                     new NotBlank(['message' => 'notBlank'])
  97.                 ]
  98.             ]);
  99.     }
  100.     public function configureOptions(OptionsResolver $resolver): void
  101.     {
  102.         $resolver->setDefaults([
  103.             'data_class' => Contact::class,
  104.         ]);
  105.     }
  106. }