<?php
declare(strict_types=1);
namespace App\Form\Type;
use App\Enum\MessageTypeEnum;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\EnumType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
class MessageFormType extends AbstractType
{
private TranslatorInterface $translator;
public function __construct(TranslatorInterface $translator)
{
$this->translator = $translator;
}
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$typeChoices = [];
foreach (MessageTypeEnum::cases() as $case) {
if ($case) {
$label = $this->translator->trans(('message.' . $case), [], 'enum');
$typeChoices[$label] = $case;
}
}
$builder
->add('type', ChoiceType::class, [ 'choices' => $typeChoices ])
->add('name', TextType::class)
->add('phoneNumber', TextType::class)
->add('email', EmailType::class)
->add('message', TextareaType::class)
->add('privacyPolicyAccepted', CheckboxType::class)
->add('send', SubmitType::class);
}
}