/** * @param \Symfony\Component\Form\FormEvent $event */ public function onBind(FormEvent $event) { $collection = $event->getForm()->getData(); $data = $event->getData(); // looks like there is no way to remove other listeners $event->stopPropagation(); if (!$collection) { $collection = $data; } elseif (count($data) === 0) { $this->modelManager->collectionClear($collection); } else { // merge $data into $collection foreach ($collection as $entity) { if (!$this->modelManager->collectionHasElement($data, $entity)) { $this->modelManager->collectionRemoveElement($collection, $entity); } else { $this->modelManager->collectionRemoveElement($data, $entity); } } foreach ($data as $entity) { $this->modelManager->collectionAddElement($collection, $entity); } } $event->setData($collection); }
/** * @param FormEvent $event */ public function onPostSubmit(FormEvent $event) { $form = $event->getForm()->get('_xml_http_request'); if ($form->getData() === 'true') { $form->addError(new FormError('The validation has been disabled.')); $event->stopPropagation(); } }
/** * @param FormEvent $event */ public function postSubmit(FormEvent $event) { $event->stopPropagation(); }