<?php
namespace App\Form;
use App\Entity\Contact;
use App\Repository\ContactRepository;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Validator\Constraints\NotBlank;
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\TextareaType;
class ContactType extends AbstractType
{
protected $contactRepository;
protected $project;
public function __construct(ContactRepository $contactRepository, $project)
{
$this->contactRepository = $contactRepository;
$this->project = $project;
}
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('lastname', TextType::class, [
'label' => false,
'attr' => [
'class' => 'form-control form-control-lg',
'placeholder' => 'Contact.input.lastname.placeholder'
],
'row_attr' => ['class' => 'col-xl-6'],
'required' => false,
'constraints' => [
new NotBlank(['message' => 'notBlank'])
]
])
->add('firstname', TextType::class, [
'label' => false,
'attr' => [
'class' => 'form-control form-control-lg',
'placeholder' => 'Contact.input.firstname.placeholder'
],
'row_attr' => ['class' => 'col-xl-6'],
'required' => false,
'constraints' => [
new NotBlank(['message' => 'notBlank'])
]
])
->add('email', EmailType::class, [
'label' => false,
'attr' => [
'class' => 'form-control form-control-lg',
'placeholder' => 'Contact.input.email.placeholder'
],
'row_attr' => ['class' => 'col-xl-6'],
'required' => false,
'constraints' => [
new NotBlank(['message' => 'notBlank'])
]
])
->add('phone', TextType::class, [
'label' => false,
'attr' => [
'class' => 'form-control form-control-lg',
'placeholder' => 'Contact.input.phone.placeholder'
],
'row_attr' => ['class' => 'col-xl-6'],
'required' => false,
'constraints' => [
new NotBlank(['message' => 'notBlank'])
]
]);
if ($this->project != 'CONFERENCE') {
$builder
->add('service', ChoiceType::class, [
'label' => false,
'attr' => [
'class' => 'form-select form-control-lg'
],
'placeholder' => 'Contact.input.service.placeholder',
'choices' => $this->contactRepository->getServices($this->project),
'required' => false,
'row_attr' => ['class' => 'col-xl-12'],
'constraints' => [
new NotBlank(['message' => 'notBlank'])
]
]);
}
$builder
->add('message', TextareaType::class, [
'label' => false,
'attr' => ['placeholder' => 'Contact.input.message.placeholder'],
'row_attr' => ['class' => 'col-xl-12'],
'required' => false,
'constraints' => [
new NotBlank(['message' => 'notBlank'])
]
]);
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => Contact::class,
]);
}
}