<?php
namespace App\Form;
use App\Entity\Contact;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Contracts\Translation\TranslatorInterface;
class ContactType extends AbstractType
{
private $router;
private $translator;
public function __construct(UrlGeneratorInterface $router, TranslatorInterface $translator)
{
$this->router = $router;
$this->translator = $translator;
}
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('lastname', null, [
"constraints" => [new NotBlank()]
])
->add('firstname', null, [
])
->add('company', null, [
"constraints" => [new NotBlank()]
])
->add('email', null, [
"constraints" => [new NotBlank()]
])
->add('phoneNumber', null, [
])
->add('address', null, [
])
->add('zipCode', null, [
])
->add('city', null, [
])
->add('subject', null, [
"constraints" => [new NotBlank()]
])
->add('message', null, [
"constraints" => [new NotBlank()],
"data" => $options["application"] ? $this->translator->trans("contact_type.message.application", ["%title%" => $options["application"]->getTitle()]) : ($options["product"] ? $this->translator->trans("contact_type.message.product", ["%title%" => $options["product"]->getTitle()]) : ($options["fabrication"] ? $this->translator->trans("contact_type.message.fabrication") : null)),
"attr" => [
"rows" => 5
]
])
->add('customFiles', CollectionType::class, array(
'entry_type' => CustomFileType::class,
'entry_options' => array('label' => false),
'allow_add' => true,
'by_reference' => false,
'allow_delete' => true,
"label" => false,
//'by_reference' => false,
))
->add("condition", CheckboxType::class, [
"mapped" => false,
"required" => true,
"label_attr" => [
"class" => "fw-400 checkbox-custom"
],
'label' => 'contact_type.condition_label',
'label_translation_parameters' => [
'%url%' => $this->router->generate('front_privacy_policy'),
],
"label_html" => true,
]);
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => Contact::class,
"application" => null,
"fabrication" => null,
"product" => null
]);
}
}