<?php
declare(strict_types=1);
namespace App\Form;
use App\Entity\Contact;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Contracts\Translation\TranslatorInterface;
class ContactType extends AbstractType
{
private TranslatorInterface $translator;
public function __construct(TranslatorInterface $translator)
{
$this->translator = $translator;
}
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add(
'name',
TextType::class,
[
'label' => false,
'attr' => [
'placeholder' => $this->translator->trans('form.name'),
],
]
)
->add(
'lastName',
TextType::class,
[
'label' => false,
'attr' => [
'placeholder' => $this->translator->trans('form.lastname'),
],
]
)
->add(
'email',
TextType::class,
[
'label' => false,
'attr' => [
'placeholder' => $this->translator->trans('form.email'),
],
]
)
->add(
'message',
TextareaType::class,
[
'label' => false,
'attr' => [
'placeholder' => $this->translator->trans('form.message'),
'rows' => '5',
],
]
)
;
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => Contact::class,
]);
}
}