src/Form/Request/RequestFormType.php line 185

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. use App\Entity\Client\Client;
  21. use App\Entity\Product\Product;
  22. use App\Entity\Project\Project;
  23. use App\Entity\Request\Priority;
  24. use App\Entity\Request\RequestType;
  25. use App\Repository\Client\ClientRepository;
  26. use App\Entity\User\User;
  27. class RequestFormType extends AbstractType
  28. {
  29.     public function __construct(
  30.         private TranslationSpecificRepository $translationSpecificRepository
  31.     )
  32.     { }
  33.     public function buildForm(FormBuilderInterface $builder, array $options): void
  34.     {
  35.         $step $options['step'];
  36.         
  37.         if($step != 'change_status'){
  38.             $builder
  39.                 ->add('extraFileds'CollectionType::class, [
  40.                     'entry_type' => RequestExtraType::class, 
  41.                     'label' => false,
  42.                     'allow_add' => true,
  43.                     'allow_delete' => true,
  44.                     'by_reference' => false,
  45.                     'required' => false,
  46.                     'mapped' => false
  47.                 ])
  48.          /* $builder
  49.                 ->add('descriptionForm', TextareaType::class, [
  50.                     'attr' => [
  51.                         'class' => 'radius_10 form_for_other'
  52.                     ],
  53.                     'required' => false,
  54.                 ])
  55.                 ->add('media', MediaType::class, [
  56.                     'label' =>  false,
  57.                     'noTitle'  => true,
  58.                     'mapped' => false,
  59.                     'required' => false,
  60.                     'accept_file_type' => 'image/png, image/svg+xml, image/jpeg, image/jpg',
  61.                     'constraints_file' => [
  62.                         new Image([
  63.                             'mimeTypes' => [
  64.                                 'image/png',
  65.                                 'image/svg+xml',
  66.                                 'image/jpeg',
  67.                                 'image/jpg'
  68.                             ],
  69.                             'mimeTypesMessage' => 'incompatible_file_type',
  70.                         ])
  71.                     ]
  72.                 ])*/
  73.                   
  74.                 ->add('name'null, [
  75.                     'attr' => [
  76.                         'class' => 'radius_10'
  77.                     ],
  78.                     'label' => false,
  79.                 ])
  80.                 ->add('company'null, [
  81.                     'attr' => [
  82.                         'class' => 'radius_10'
  83.                     ],
  84.                     'label' => false,
  85.                 ])
  86.                 ->add('email'null, [
  87.                     'attr' => [
  88.                         'class' => 'radius_10'
  89.                     ],
  90.                     'label' => false
  91.                 ])
  92.                 ->add('telephone'null, [
  93.                     'attr' => [
  94.                         'class' => 'radius_10'
  95.                     ],
  96.                     'label' => false
  97.                 ])
  98.                 ->add('email_honeypot'HoneypotType::class)
  99.                 /*->add('captcha', CaptchaType::class, [
  100.                         'bypass_code' => 'asas',
  101.                 ])*/
  102.             ;
  103.         }
  104.         if($step == 'change_status') {
  105.             $builder    
  106.             ->add('requestStatus'EntityType::class, [
  107.                 'class' => RequestStatus::class,
  108.                 'choice_label' => function (RequestStatus $item) use ($options) {
  109.                     $data $this->translationSpecificRepository->findOneBy([
  110.                         'fk' => 'request_status.label',
  111.                         'language' => $options['language'],
  112.                         'refId' => $item->getId()
  113.                     ]);
  114.                     return  $data $data->getValueText() : null;
  115.                 },
  116.                 'query_builder' => function(RequestStatusRepository $repository) { 
  117.                     return $repository
  118.                     ->createQueryBuilder('rs')
  119.                     ->where('rs.isEnable = 1')
  120.                     ->andWhere('rs.deletedAt IS NULL')
  121.                 ;
  122.                 },
  123.                 'required' => true,
  124.                 'multiple' => false
  125.                 'placeholder' => "",
  126.                 'constraints' => [],
  127.                 'attr' => ['class' => 'search-select2'], 
  128.                 'label' => false
  129.             ])
  130.                  
  131.             ;
  132.         } 
  133.         $builder    
  134.             ->add('client'EntityType::class, [
  135.                 'class' => Client::class,
  136.                 'choice_label' => function (Client $item) use ($options) {
  137.                     return  $item $item->getName() : '';
  138.                 },
  139.                 'query_builder' => function(ClientRepository $repository) { 
  140.                     return $repository
  141.                     ->createQueryBuilder('c')
  142.                     ->where('c.isEnable = 1')
  143.                     ->andWhere('c.deletedAt IS NULL')
  144.                 ;
  145.                 },
  146.                 'required' => false,
  147.                 'multiple' => false
  148.                 'placeholder' => "",
  149.                 'constraints' => [],
  150.                 'attr' => ['class' => 'search-select2'], 
  151.                 'label' => false
  152.             ])
  153.             ->add('product'EntityType::class, [
  154.                 'class' => Product::class,
  155.                 'choice_label' => function (Product $item) use ($options) {
  156.                     return  $item $item->getName() : '';
  157.                 },
  158.                 'required' => false,
  159.                 'multiple' => false
  160.                 'placeholder' => "",
  161.                 'constraints' => [],
  162.                 'attr' => ['class' => 'search-select2'], 
  163.                 'label' => false
  164.             ])
  165.             ->add('project'EntityType::class, [
  166.                 'class' => Project::class,
  167.                 'choice_label' => function (Project $item) use ($options) {
  168.                     return  $item $item->getName() : '';
  169.                 },
  170.                 'required' => false,
  171.                 'multiple' => false
  172.                 'placeholder' => "",
  173.                 'constraints' => [],
  174.                 'attr' => ['class' => 'search-select2'], 
  175.                 'label' => false
  176.             ])
  177.             ->add('priority'EntityType::class, [
  178.                 'class' => Priority::class,
  179.                 'choice_label' => function (Priority $item) use ($options) {
  180.                     return  $item $item->getLabel() : '';
  181.                 },
  182.                 'required' => false,
  183.                 'multiple' => false
  184.                 'placeholder' => "",
  185.                 'constraints' => [],
  186.                 'attr' => ['class' => 'search-select2'], 
  187.                 'label' => false
  188.             ])
  189.             ->add('requestType'EntityType::class, [
  190.                 'class' => RequestType::class,
  191.                 'choice_label' => function (RequestType $item) use ($options) {
  192.                     return  $item $item->getLabel() : '';
  193.                 },
  194.                 'required' => false,
  195.                 'multiple' => false
  196.                 'placeholder' => "",
  197.                 'constraints' => [],
  198.                 'attr' => ['class' => 'search-select2'], 
  199.                 'label' => false
  200.             ])
  201.             ->add('user'EntityType::class, [
  202.                 'class' => User::class,
  203.                 'choice_label' => function (User $item) use ($options) {
  204.                     return  $item->getEmail();
  205.                 },
  206.                 'required' => false,
  207.                 'multiple' => false
  208.                 'placeholder' => "",
  209.                 'constraints' => [],
  210.                 'attr' => ['class' => 'search-select2'], 
  211.                 'label' => false
  212.             ])
  213.                  
  214.             ;
  215.     }
  216.     public function configureOptions(OptionsResolver $resolver): void
  217.     {
  218.         $resolver->setDefaults([
  219.             'data_class' => RequestForm::class,
  220.             'csrf_protection' => false,
  221.             'translation_domain' => 'forms',
  222.             'step' => null,
  223.             'language' => null
  224.         ]);
  225.     }
  226. }