src/Form/ContactType.php line 16

Open in your IDE?
  1. <?php
  2. namespace App\Form;
  3. use App\Entity\Contact;
  4. use Symfony\Component\Form\AbstractType;
  5. use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
  6. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  7. use Symfony\Component\Form\Extension\Core\Type\CollectionType;
  8. use Symfony\Component\Form\FormBuilderInterface;
  9. use Symfony\Component\OptionsResolver\OptionsResolver;
  10. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  11. use Symfony\Component\Validator\Constraints\NotBlank;
  12. use Symfony\Contracts\Translation\TranslatorInterface;
  13. class ContactType extends AbstractType
  14. {
  15.     private $router;
  16.     private $translator;
  17.     public function __construct(UrlGeneratorInterface $routerTranslatorInterface $translator)
  18.     {
  19.         $this->router $router;
  20.         $this->translator $translator;
  21.     }
  22.     public function buildForm(FormBuilderInterface $builder, array $options): void
  23.     {
  24.         $product $options["product"];
  25.         $builder
  26.             ->add('company'null, [
  27.                 "required"=>true,
  28.                 "constraints" => [new NotBlank()]
  29.             ])
  30.             ->add('firstname'null, [
  31.             ])
  32.             ->add('lastname'null, [
  33.                 "required"=>true,
  34.                 "constraints" => [new NotBlank()]
  35.             ])
  36.             ->add('address'null, [
  37.             ])
  38.             ->add('zipCode'null, [
  39.                 "required"=>true,
  40.                 "constraints" => [new NotBlank()]
  41.             ])
  42.             ->add('city'null, [
  43.                 "required"=>true,
  44.                 "constraints" => [new NotBlank()]
  45.             ])
  46.             ->add('country'null, [
  47.                 "required"=>true,
  48.                 "constraints" => [new NotBlank()]
  49.             ])
  50.             ->add('email'null, [
  51.                 "required"=>true,
  52.                 "constraints" => [new NotBlank()]
  53.             ])
  54.             ->add('phoneNumber'null, [
  55.                 "required"=>true,
  56.                 "constraints" => [new NotBlank()]
  57.             ])
  58.             ->add('subject'ChoiceType::class, array(
  59.                 'placeholder' => "contact.subject.placeholder",
  60.                 'choices' => [
  61.                     "Demande d’informations" => "Demande d’informations",
  62.                     "Demande de devis" => "Demande de devis",
  63.                     "Autre" => "Autre"],
  64.                 "attr" => array(
  65.                     "class" => "no-selectpicker",
  66.                 ),
  67.                 'multiple' => false,
  68.                 'expanded' => false,
  69.                 'required' => false
  70.             ))
  71.             ->add('message'null, [
  72.                 "data" => $product $this->translator->trans("contact_type.message.data", ["%product%" => $product->getTitle()]) : null,
  73.                 "required"=>true,
  74.                 "constraints" => [new NotBlank()],
  75.                 "attr" => [
  76.                     "rows" => 5
  77.                 ]
  78.             ])
  79. //            ->add('customFiles', CollectionType::class, array(
  80. //                'entry_type' => CustomFileType::class,
  81. //                'entry_options' => array('label' => false),
  82. //                'allow_add' => true,
  83. //                'by_reference' => false,
  84. //                'allow_delete' => true,
  85. //                "label" => false,
  86. //                //'by_reference' => false,
  87. //            ))
  88.             ->add("condition"CheckboxType::class, [
  89.                 "mapped" => false,
  90.                 "required" => true,
  91.                 "label_attr" => [
  92.                     "class" => "fw-400 checkbox-custom"
  93.                 ],
  94.                 'label' => 'contact_type.condition_label',
  95.                 'label_translation_parameters' => [
  96.                     '%url%' => $this->router->generate('front_privacy_policy'),
  97.                 ],
  98.                 "label_html" => true,
  99.             ]);
  100.     }
  101.     public function configureOptions(OptionsResolver $resolver): void
  102.     {
  103.         $resolver->setDefaults([
  104.             'data_class' => Contact::class,
  105.             'product' => null,
  106.         ]);
  107.     }
  108. }