src/Form/ContactType.php line 15

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Form;
  4. use App\Entity\Contact;
  5. use Symfony\Component\Form\AbstractType;
  6. use Symfony\Component\Form\Extension\Core\Type\TextareaType;
  7. use Symfony\Component\Form\Extension\Core\Type\TextType;
  8. use Symfony\Component\Form\FormBuilderInterface;
  9. use Symfony\Component\OptionsResolver\OptionsResolver;
  10. use Symfony\Contracts\Translation\TranslatorInterface;
  11. class ContactType extends AbstractType
  12. {
  13.     private TranslatorInterface $translator;
  14.     public function __construct(TranslatorInterface $translator)
  15.     {
  16.         $this->translator $translator;
  17.     }
  18.     public function buildForm(FormBuilderInterface $builder, array $options)
  19.     {
  20.         $builder
  21.             ->add(
  22.                 'name',
  23.                 TextType::class,
  24.                 [
  25.                 'label' => false,
  26.                 'attr' => [
  27.                         'placeholder' => $this->translator->trans('form.name'),
  28.                     ],
  29.                 ]
  30.             )
  31.             ->add(
  32.                 'lastName',
  33.                 TextType::class,
  34.                 [
  35.                 'label' => false,
  36.                 'attr' => [
  37.                         'placeholder' => $this->translator->trans('form.lastname'),
  38.                     ],
  39.                 ]
  40.             )
  41.             ->add(
  42.                 'email',
  43.                 TextType::class,
  44.                 [
  45.                 'label' => false,
  46.                 'attr' => [
  47.                         'placeholder' => $this->translator->trans('form.email'),
  48.                     ],
  49.                 ]
  50.             )
  51.             ->add(
  52.                 'message',
  53.                 TextareaType::class,
  54.                 [
  55.                 'label' => false,
  56.                 'attr' => [
  57.                         'placeholder' => $this->translator->trans('form.message'),
  58.                         'rows' => '5',
  59.                     ],
  60.                 ]
  61.             )
  62.         ;
  63.     }
  64.     public function configureOptions(OptionsResolver $resolver)
  65.     {
  66.         $resolver->setDefaults([
  67.             'data_class' => Contact::class,
  68.         ]);
  69.     }
  70. }