src/Form/CustomerServiceType.php line 20

  1. <?php
  2. namespace App\Form;
  3. use Symfony\Component\Form\AbstractType;
  4. use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
  5. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  6. use Symfony\Component\Form\Extension\Core\Type\DateType;
  7. use Symfony\Component\Form\Extension\Core\Type\EmailType;
  8. use Symfony\Component\Form\Extension\Core\Type\FileType;
  9. use Symfony\Component\Form\Extension\Core\Type\TelType;
  10. use Symfony\Component\Form\Extension\Core\Type\TextareaType;
  11. use Symfony\Component\Form\Extension\Core\Type\TextType;
  12. use Symfony\Component\Form\FormBuilderInterface;
  13. use Symfony\Component\OptionsResolver\OptionsResolver;
  14. use Symfony\Component\Validator\Constraints\File;
  15. use Symfony\Component\Validator\Constraints as Assert;
  16. use Symfony\Contracts\Translation\TranslatorInterface;
  17. class CustomerServiceType extends AbstractType
  18. {
  19.     private $transalor;
  20.     public function __construct(TranslatorInterface $translator)
  21.     {
  22.         $this->transalor $translator;
  23.     }
  24.     public function buildForm(FormBuilderInterface $builder, array $options): void
  25.     {
  26.         $builder
  27.             ->add('name'TextType::class)
  28.             ->add('surname'TextType::class)
  29.             ->add('email'EmailType::class)
  30.             ->add('phone'TelType::class)
  31.             ->add('reason'ChoiceType::class,[
  32.                 'required' => true,
  33.                 'choices' => [
  34.                     $this->transalor->trans('form.labels.customer_service.reason') => null,
  35.                     $this->transalor->trans('form.choices.customer_service.product_reports') => 1,
  36.                     $this->transalor->trans('form.choices.customer_service.product_informations') => 2,
  37.                     $this->transalor->trans('form.choices.customer_service.product_location') => 3,
  38.                     $this->transalor->trans('form.common_values.other') => 4,
  39.                 ],
  40.                 'constraints' => [
  41.                     new Assert\NotNull([
  42.                     ])
  43.                 ]
  44.             ])
  45.             ->add('productName'TextType::class, [
  46.                 'attr' => [
  47.                     'class' => 'product-report'
  48.                 ]
  49.             ])
  50.             ->add('productionLot'TextType::class)
  51.             ->add('expirationDate'DateType::class,[
  52.                 'widget' => 'single_text',
  53.             ])
  54.             ->add('productRetirament'ChoiceType::class,[
  55.                 'required' => true,
  56.                 'choices' => [
  57.                     $this->transalor->trans('form.common_values.no') => 'no',
  58.                     $this->transalor->trans('form.common_values.yes') => 'yes',
  59.                 ]
  60.             ])
  61.             ->add('file'FileType::class, [
  62.                 'required' => true,
  63.                 'constraints' => [
  64.                     new Assert\File([
  65.                         'maxSize' => '8M',
  66.                         'mimeTypes' => [
  67.                             'image/jpeg',
  68.                             'image/jpg',
  69.                             'image/png',
  70.                             'application/pdf',
  71.                             'application/x-pdf',
  72.                         ],
  73.                         'mimeTypesMessage' => $this->transalor->trans('form.errors.wrong_file_type'),
  74.                     ])
  75.                 ],
  76.             ])
  77.             ->add('city'TextType::class)
  78.             ->add('message'TextareaType::class)
  79.             ->add('privacy'CheckboxType::class)
  80.             ->add('data'ChoiceType::class, [
  81.                 'choices' => [
  82.                     $this->transalor->trans('form.choices.privacy.not_agree') => 0,
  83.                     $this->transalor->trans('form.choices.privacy.agree') => 1
  84.                 ],
  85.                 'required' => true,
  86.                 'expanded' => true
  87.             ])
  88.             // ->add('data2', ChoiceType::class, [
  89.             //     'choices' => [
  90.             //         $this->transalor->trans('form.choices.privacy.not_agree') => 0,
  91.             //         $this->transalor->trans('form.choices.privacy.agree') => 1
  92.             //     ],
  93.             //     'required' => true,
  94.             //     'expanded' => true
  95.             // ])
  96.         ;
  97.     }
  98.     public function configureOptions(OptionsResolver $resolver): void
  99.     {
  100.         $resolver->setDefaults([
  101.             // 'mapped' => false,
  102.         ]);
  103.     }
  104. }