TheCelavi

Form issue -> this works, why?

Dec 28th, 2016
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.43 KB | None | 0 0
  1. <?php
  2.  
  3. namespace Louis\DataImportBundle\Form\Type\Halcom;
  4.  
  5. use Louis\CoreBundle\Entity\Invoice\Payment;
  6. use Louis\CoreBundle\Entity\Transaction\TransactionFee;
  7. use Louis\DataImportBundle\Form\Type\PaymentType;
  8. use Louis\DataImportBundle\Form\Type\TransactionFeeType;
  9. use Symfony\Component\Form\AbstractType;
  10. use Symfony\Component\Form\Extension\Core\Type\CollectionType;
  11. use Symfony\Component\Form\FormBuilderInterface;
  12. use Symfony\Component\Form\FormInterface;
  13. use Symfony\Component\OptionsResolver\OptionsResolver;
  14. use Symfony\Component\Validator\Constraints\Valid;
  15.  
  16. class ProcessDomesticTransactionsStatementsType extends AbstractType
  17. {
  18.     public function buildForm(FormBuilderInterface $builder, array $options)
  19.     {
  20.         parent::buildForm($builder, $options);
  21.  
  22.         $builder
  23.             ->add('payments', CollectionType::class, array(
  24.                 'entry_type' => PaymentType::class,
  25.                 'entry_options' => [
  26.                     'data_class' => Payment::class,
  27.                     'constraints' => new Valid(),
  28.                     'validation_groups' => function(FormInterface $form) {
  29.                         if (false === $form->get('import')->getData()) {
  30.                             return ['__DOES_NOT_EXISTS__'];
  31.                         }
  32.  
  33.                         return ['Default'];
  34.                     }
  35.                 ],
  36.                 'allow_add' => false,
  37.                 'allow_delete' => false
  38.             ))
  39.             ->add('fees', CollectionType::class, array(
  40.                 'entry_type' => TransactionFeeType::class,
  41.                 'entry_options' => [
  42.                     'data_class' => TransactionFee::class,
  43.                     'constraints' => new Valid(),
  44.                     'validation_groups' => function(FormInterface $form) {
  45.                         if (false === $form->get('import')->getData()) {
  46.                             return ['__DOES_NOT_EXISTS__'];
  47.                         }
  48.  
  49.                         return ['Default'];
  50.                     }
  51.                 ],
  52.                 'allow_add' => false,
  53.                 'allow_delete' => false
  54.             ))
  55.         ;
  56.     }
  57.  
  58.     public function configureOptions(OptionsResolver $resolver)
  59.     {
  60.         $resolver
  61.             ->setDefault('novalidate', true)
  62.             ->setDefault('validation_groups', function () {
  63.                 return ['__DOES_NOT_EXISTS__'];
  64.             })
  65.         ;
  66.     }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment