src/Form/NoticeType.php line 20

Open in your IDE?
  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\FormBuilderInterface;
  6. use Symfony\Component\OptionsResolver\OptionsResolver;
  7. use Symfony\Component\Form\FormEvent;
  8. use Symfony\Component\Form\FormEvents;
  9. use Symfony\Component\Form\Extension\Core\Type\CollectionType;
  10. use Symfony\Component\Form\Extension\Core\Type\TextType;
  11. use Symfony\Component\Form\Extension\Core\Type\FileType;
  12. use App\Form\NoticePodnetType;
  13. use App\Form\NoticeOznamenieType;
  14. use App\Entity\Notice;
  15. use App\Form\LocType;
  16. use App\Form\DocType;
  17. class NoticeType extends AbstractType {
  18.     private $options;
  19.     public function buildForm(FormBuilderInterface $builder, array $options) {
  20.         $this->options $options;
  21.         $builder
  22.                 ->add('nazov'TextType::class)
  23.                 ->add('locs'CollectionType::class, [
  24.                     'entry_type' => LocType::class,
  25.                     'entry_options' => [
  26.                         'ciselnikObci' => $options['ciselnikObci'],
  27.                     ],
  28.                     'prototype' => true,
  29.                     'allow_add' => true,
  30.                     'allow_delete' => true,
  31.                     'by_reference' => false,
  32.                     'required' => false,
  33.                     'label' => false,
  34.                 ])
  35.                 ->add('fileupload'FileType::class,[
  36.                     'mapped' => false,
  37.                     'required' => false,
  38.                     'label' => false,
  39.                 ])
  40.                 ->add('docs'CollectionType::class, [
  41.                     'entry_type' => DocType::class,
  42.                     'prototype' => true,
  43.                     'allow_add' => true,
  44.                     'allow_delete' => true,
  45.                     'by_reference' => false,
  46.                     'required' => false,
  47.                     'label' => false,
  48.                 ])
  49.                 ->add('operators'CollectionType::class, [
  50.                     'entry_type' => OperatorType::class,
  51.                     'entry_options' => [
  52.                         'ciselniky' => $options['ciselniky'],
  53.                     ],
  54.                     'prototype' => true,
  55.                     'allow_add' => true,
  56.                     'allow_delete' => true,
  57.                     'by_reference' => false,
  58.                     'required' => false,
  59.                     'label' => false,
  60.                 ])
  61. //            ->add('gdpr', CheckboxType::class, [
  62. //                'label' => false,
  63. //                'required' => true,
  64. //                'mapped' => false,
  65. //            ])
  66.                 ->addEventListener(
  67.                         FormEvents::PRE_SET_DATA,
  68.                         [$this'onPreSubmit']
  69.                 )
  70.         //->getForm()
  71.         ;
  72.     }
  73.     /**
  74.      * {@inheritdoc}
  75.      */
  76.     public function configureOptions(OptionsResolver $resolver) {
  77.         $resolver->setDefaults(array(
  78.             'data_class' => Notice::class,
  79.             'ciselniky' => null,
  80.             'ciselnikObci' => null,
  81.         ));
  82.     }
  83.     /**
  84.      * {@inheritdoc}
  85.      */
  86.     public function getBlockPrefix() {
  87.         return 'notice';
  88.     }
  89.     public function onPreSubmit(FormEvent $event) {
  90.         $data $event->getData();
  91.         $form $event->getForm();
  92.         if ($data->getType() == 'oznamenie') {
  93.             $form->add('oznamenie'NoticeOznamenieType::class, [
  94.                         'label' => false,
  95.                         'ciselniky' => $this->options['ciselniky'],
  96.             ]);
  97.         } else {
  98.             $form->add('nazov'TextType::class, [
  99.                         'label' => 'Názov podnetu:',
  100.                         'attr' => [
  101.                             'class' => 'form-control',
  102.                             'placeholder' => 'Názov podnetu...',
  103.                         ],
  104.                     ])
  105.                     ->add('podnet'NoticePodnetType::class, [
  106.                         'label' => false,
  107.                         'ciselniky' => $this->options['ciselniky'],
  108.             ]);
  109.         }
  110.     }
  111. }