public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $builder->add('status', 'choice', ['choices' => Orders::getStatuses(), 'required' => false])->add('user', 'entity', ['class' => 'AppBundle\\Entity\\User', 'required' => false])->add('car', 'entity', ['class' => 'AppBundle\\Entity\\Car', 'required' => false]);
     $listener = function (FormEvent $event) {
         // Is data empty?
         foreach ($event->getData() as $data) {
             if (is_array($data)) {
                 foreach ($data as $subData) {
                     if (!empty($subData)) {
                         return;
                     }
                 }
             } else {
                 if (!empty($data)) {
                     return;
                 }
             }
         }
         $event->getForm()->addError(new FormError('Filter empty'));
     };
     $builder->addEventListener(FormEvents::POST_BIND, $listener);
 }
Exemple #2
0
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $builder->add('status', 'choice', ['choices' => Orders::getStatuses()])->add('car', null, ['required' => true])->add('user', null, ['required' => true]);
 }