<?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\ChoiceType;
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
{
$product = $options["product"];
$builder
->add('company', null, [
"required"=>true,
"constraints" => [new NotBlank()]
])
->add('firstname', null, [
])
->add('lastname', null, [
"required"=>true,
"constraints" => [new NotBlank()]
])
->add('address', null, [
])
->add('zipCode', null, [
"required"=>true,
"constraints" => [new NotBlank()]
])
->add('city', null, [
"required"=>true,
"constraints" => [new NotBlank()]
])
->add('country', null, [
"required"=>true,
"constraints" => [new NotBlank()]
])
->add('email', null, [
"required"=>true,
"constraints" => [new NotBlank()]
])
->add('phoneNumber', null, [
"required"=>true,
"constraints" => [new NotBlank()]
])
->add('subject', ChoiceType::class, array(
'placeholder' => "contact.subject.placeholder",
'choices' => [
"Demande d’informations" => "Demande d’informations",
"Demande de devis" => "Demande de devis",
"Autre" => "Autre"],
"attr" => array(
"class" => "no-selectpicker",
),
'multiple' => false,
'expanded' => false,
'required' => false
))
->add('message', null, [
"data" => $product ? $this->translator->trans("contact_type.message.data", ["%product%" => $product->getTitle()]) : null,
"required"=>true,
"constraints" => [new NotBlank()],
"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,
'product' => null,
]);
}
}