src/Form/Request/RequestFormType.php line 23

Open in your IDE?
  1. <?php
  2. namespace App\Form\Request;
  3. use App\Form\MediaType;
  4. use App\Entity\Request\RequestForm;
  5. use App\Entity\TranslationSpecific;
  6. use Doctrine\Common\Util\ClassUtils;
  7. use App\Entity\Request\RequestStatus;
  8. use App\Form\Request\RequestExtraType;
  9. use Symfony\Component\Form\AbstractType;
  10. use Eo\HoneypotBundle\Form\Type\HoneypotType;
  11. use Symfony\Component\Form\FormBuilderInterface;
  12. use App\Repository\TranslationSpecificRepository;
  13. use Symfony\Bridge\Doctrine\Form\Type\EntityType;
  14. use Symfony\Component\Validator\Constraints\Image;
  15. use App\Repository\Request\RequestStatusRepository;
  16. use Symfony\Component\Validator\Constraints\NotBlank;
  17. use Symfony\Component\OptionsResolver\OptionsResolver;
  18. use Symfony\Component\Form\Extension\Core\Type\TextareaType;
  19. use Symfony\Component\Form\Extension\Core\Type\CollectionType;
  20. class RequestFormType extends AbstractType
  21. {
  22.     public function __construct(
  23.         private TranslationSpecificRepository $translationSpecificRepository
  24.     )
  25.     { }
  26.     public function buildForm(FormBuilderInterface $builder, array $options): void
  27.     {
  28.         $step $options['step'];
  29.         
  30.         if($step != 'change_status'){
  31.             $builder
  32.                 ->add('extraFileds'CollectionType::class, [
  33.                     'entry_type' => RequestExtraType::class, 
  34.                     'label' => false,
  35.                     'allow_add' => true,
  36.                     'allow_delete' => true,
  37.                     'by_reference' => false,
  38.                     'required' => false,
  39.                     'mapped' => false
  40.                 ])
  41.          /* $builder
  42.                 ->add('descriptionForm', TextareaType::class, [
  43.                     'attr' => [
  44.                         'class' => 'radius_10 form_for_other'
  45.                     ],
  46.                     'required' => false,
  47.                 ])
  48.                 ->add('media', MediaType::class, [
  49.                     'label' =>  false,
  50.                     'noTitle'  => true,
  51.                     'mapped' => false,
  52.                     'required' => false,
  53.                     'accept_file_type' => 'image/png, image/svg+xml, image/jpeg, image/jpg',
  54.                     'constraints_file' => [
  55.                         new Image([
  56.                             'mimeTypes' => [
  57.                                 'image/png',
  58.                                 'image/svg+xml',
  59.                                 'image/jpeg',
  60.                                 'image/jpg'
  61.                             ],
  62.                             'mimeTypesMessage' => 'incompatible_file_type',
  63.                         ])
  64.                     ]
  65.                 ])*/
  66.                   
  67.                 ->add('name'null, [
  68.                     'attr' => [
  69.                         'class' => 'radius_10'
  70.                     ],
  71.                     'label' => false,
  72.                 ])
  73.                 ->add('company'null, [
  74.                     'attr' => [
  75.                         'class' => 'radius_10'
  76.                     ],
  77.                     'label' => false,
  78.                 ])
  79.                 ->add('email'null, [
  80.                     'attr' => [
  81.                         'class' => 'radius_10'
  82.                     ],
  83.                     'label' => false
  84.                 ])
  85.                 ->add('telephone'null, [
  86.                     'attr' => [
  87.                         'class' => 'radius_10'
  88.                     ],
  89.                     'label' => false
  90.                 ])
  91.                 ->add('email_honeypot'HoneypotType::class)
  92.                 /*->add('captcha', CaptchaType::class, [
  93.                         'bypass_code' => 'asas',
  94.                 ])*/
  95.             ;
  96.         }
  97.         if($step == 'change_status') {
  98.             $builder    
  99.             ->add('requestStatus'EntityType::class, [
  100.                 'class' => RequestStatus::class,
  101.                 'choice_label' => function (RequestStatus $item) use ($options) {
  102.                     $data $this->translationSpecificRepository->findOneBy([
  103.                         'fk' => 'request_status.label',
  104.                         'language' => $options['language'],
  105.                         'refId' => $item->getId()
  106.                     ]);
  107.                     return  $data $data->getValueText() : null;
  108.                 },
  109.                 'query_builder' => function(RequestStatusRepository $repository) { 
  110.                     return $repository
  111.                     ->createQueryBuilder('rs')
  112.                     ->where('rs.isEnable = 1')
  113.                     ->andWhere('rs.deletedAt IS NULL')
  114.                 ;
  115.                 },
  116.                 'required' => true,
  117.                 'multiple' => false
  118.                 'placeholder' => "",
  119.                 'constraints' => [],
  120.                 'attr' => ['class' => 'search-select2'], 
  121.                 'label' => false
  122.             ])
  123.                  
  124.             ;
  125.         } 
  126.     }
  127.     public function configureOptions(OptionsResolver $resolver): void
  128.     {
  129.         $resolver->setDefaults([
  130.             'data_class' => RequestForm::class,
  131.             'csrf_protection' => false,
  132.             'translation_domain' => 'forms',
  133.             'step' => null,
  134.             'language' => null
  135.         ]);
  136.     }
  137. }