src/Form/ContactType.php line 15

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\CollectionType;
  7. use Symfony\Component\Form\FormBuilderInterface;
  8. use Symfony\Component\OptionsResolver\OptionsResolver;
  9. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  10. use Symfony\Component\Validator\Constraints\NotBlank;
  11. use Symfony\Contracts\Translation\TranslatorInterface;
  12. class ContactType extends AbstractType
  13. {
  14.     private $router;
  15.     private $translator;
  16.     public function __construct(UrlGeneratorInterface $routerTranslatorInterface $translator)
  17.     {
  18.         $this->router $router;
  19.         $this->translator $translator;
  20.     }
  21.     public function buildForm(FormBuilderInterface $builder, array $options): void
  22.     {
  23.         $builder
  24.             ->add('lastname'null, [
  25.                 "constraints" => [new NotBlank()]
  26.             ])
  27.             ->add('firstname'null, [
  28.             ])
  29.             ->add('company'null, [
  30.                 "constraints" => [new NotBlank()]
  31.             ])
  32.             ->add('email'null, [
  33.                 "constraints" => [new NotBlank()]
  34.             ])
  35.             ->add('phoneNumber'null, [
  36.             ])
  37.             ->add('address'null, [
  38.             ])
  39.             ->add('zipCode'null, [
  40.             ])
  41.             ->add('city'null, [
  42.             ])
  43.             ->add('subject'null, [
  44.                 "constraints" => [new NotBlank()]
  45.             ])
  46.             ->add('message'null, [
  47.                 "constraints" => [new NotBlank()],
  48.                 "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)),
  49.                 "attr" => [
  50.                     "rows" => 5
  51.                 ]
  52.             ])
  53.             ->add('customFiles'CollectionType::class, array(
  54.                 'entry_type' => CustomFileType::class,
  55.                 'entry_options' => array('label' => false),
  56.                 'allow_add' => true,
  57.                 'by_reference' => false,
  58.                 'allow_delete' => true,
  59.                 "label" => false,
  60.                 //'by_reference' => false,
  61.             ))
  62.             ->add("condition"CheckboxType::class, [
  63.                 "mapped" => false,
  64.                 "required" => true,
  65.                 "label_attr" => [
  66.                     "class" => "fw-400 checkbox-custom"
  67.                 ],
  68.                 'label' => 'contact_type.condition_label',
  69.                 'label_translation_parameters' => [
  70.                     '%url%' => $this->router->generate('front_privacy_policy'),
  71.                 ],
  72.                 "label_html" => true,
  73.             ]);
  74.     }
  75.     public function configureOptions(OptionsResolver $resolver): void
  76.     {
  77.         $resolver->setDefaults([
  78.             'data_class' => Contact::class,
  79.             "application" => null,
  80.             "fabrication" => null,
  81.             "product" => null
  82.         ]);
  83.     }
  84. }