/** * @param \FSi\Bundle\AdminBundle\Event\FormEvent $event * @param \Symfony\Component\Form\Form $form * @param \FSi\Bundle\AdminBundle\Message\FlashMessages $flashMessages */ public function it_set_error_message_when_form_is_invalid($event, $form, $flashMessages) { $event->getForm()->willReturn($form); $form->isValid()->willReturn(false); $flashMessages->error('messages.form.error')->shouldBeCalled(); $this->onFormRequestPostSubmit($event); }
/** * @param \FSi\Bundle\AdminBundle\Event\FormEvent $event * @param \Symfony\Component\HttpFoundation\Request $request */ protected function action(FormEvent $event, Request $request) { /** @var \FSi\Bundle\AdminBundle\Admin\CRUD\BatchElement $element */ $element = $event->getElement(); $objects = $this->getObjects($element, $request); foreach ($objects as $object) { $element->apply($object); } }
/** * @param \FSi\Bundle\AdminBundle\Event\FormEvent $event */ protected function action(FormEvent $event, Request $request) { /* @var $element \FSi\Bundle\AdminBundle\Admin\ResourceRepository\GenericResourceElement */ $element = $event->getElement(); $data = $event->getForm()->getData(); foreach ($data as $resource) { $element->save($resource); } }
/** * @param \FSi\Bundle\AdminBundle\Event\FormEvent $event * @param \Symfony\Component\HttpFoundation\Request $request * @param \Symfony\Component\HttpFoundation\ParameterBag $requestParameterbag * @param \Symfony\Component\EventDispatcher\EventDispatcher $eventDispatcher * @param \Symfony\Component\Form\Form $form * @param \FSi\Bundle\AdminBundle\Admin\CRUD\BatchElement $element * @param \FSi\Component\DataIndexer\DataIndexerInterface $dataIndexer */ function it_return_response_from_post_apply_event($event, $request, $requestParameterbag, $eventDispatcher, $form, $element, $dataIndexer) { $request->isMethod('POST')->willReturn(true); $request->request = $requestParameterbag; $requestParameterbag->get('indexes', array())->willReturn(array('index')); $event->getForm()->willReturn($form); $form->isValid()->willReturn(true); $eventDispatcher->dispatch(BatchEvents::BATCH_OBJECTS_PRE_APPLY, $event)->shouldBeCalled(); $form->getData()->willReturn(new \stdClass()); $event->getElement()->willReturn($element); $element->getDataIndexer()->willReturn($dataIndexer); $dataIndexer->getData('index')->willReturn(new \stdClass()); $element->apply(Argument::type('stdClass'))->shouldBeCalled(); $eventDispatcher->dispatch(BatchEvents::BATCH_OBJECTS_POST_APPLY, $event)->will(function () use($event) { $event->hasResponse()->willReturn(true); $event->getResponse()->willReturn(new Response()); }); $this->handleRequest($event, $request)->shouldReturnAnInstanceOf('Symfony\\Component\\HttpFoundation\\Response'); }
/** * @param \Symfony\Component\EventDispatcher\EventDispatcher $eventDispatcher * @param \FSi\Bundle\AdminBundle\Event\FormEvent $event */ function let($eventDispatcher, $event) { $event->hasResponse()->willReturn(false); $this->beConstructedWith($eventDispatcher); }
public function onFormRequestPostSubmit(FormEvent $event) { if (!$event->getForm()->isValid()) { $this->flashMessages->error('messages.form.error'); } }
/** * @param \FSi\Bundle\AdminBundle\Event\FormEvent $event * @param \Symfony\Component\HttpFoundation\Request $request */ protected function action(FormEvent $event, Request $request) { $event->getElement()->save($event->getForm()->getData()); }
/** * @param \FSi\Bundle\AdminBundle\Event\FormEvent $event * @param \Symfony\Component\HttpFoundation\Request $request * @return \Symfony\Component\HttpFoundation\RedirectResponse */ protected function getRedirectResponse(FormEvent $event, Request $request) { /** @var \FSi\Bundle\AdminBundle\Admin\RedirectableElement $element */ $element = $event->getElement(); return new RedirectResponse($this->router->generate($element->getSuccessRoute(), $element->getSuccessRouteParameters())); }
/** * @param \FSi\Bundle\AdminBundle\Event\FormEvent $event * @param \Symfony\Component\HttpFoundation\Request $request * @param \Symfony\Component\EventDispatcher\EventDispatcher $eventDispatcher * @param \Symfony\Component\Form\Form $form * @param \FSi\Bundle\AdminBundle\Doctrine\Admin\ResourceElement $element */ function it_return_response_from_post_entity_save_event($event, $request, $eventDispatcher, $form, $element) { $request->isMethod('POST')->willReturn(true); $event->getForm()->willReturn($form); $form->isValid()->willReturn(true); $eventDispatcher->dispatch(FormEvents::FORM_DATA_PRE_SAVE, $event)->shouldBeCalled(); $form->getData()->willReturn(array(new Resource(), new Resource())); $event->getElement()->willReturn($element); $element->save(Argument::type('FSi\\Bundle\\AdminBundle\\spec\\fixtures\\Entity\\Resource'))->shouldBeCalledTimes(2); $eventDispatcher->dispatch(FormEvents::FORM_DATA_POST_SAVE, $event)->will(function () use($event) { $event->hasResponse()->willReturn(true); $event->getResponse()->willReturn(new Response()); }); $this->handleRequest($event, $request)->shouldReturnAnInstanceOf('Symfony\\Component\\HttpFoundation\\Response'); }
/** * @param \FSi\Bundle\AdminBundle\Event\FormEvent $event * @param \Symfony\Component\HttpFoundation\Request $request * @param \Symfony\Component\EventDispatcher\EventDispatcher $eventDispatcher * @param \Symfony\Component\Form\Form $form * @param \FSi\Bundle\AdminBundle\Admin\CRUD\FormElement $element */ function it_return_response_from_post_data_save_event($event, $request, $eventDispatcher, $form, $element) { $request->isMethod('POST')->willReturn(true); $event->getForm()->willReturn($form); $form->isValid()->willReturn(true); $eventDispatcher->dispatch(FormEvents::FORM_DATA_PRE_SAVE, $event)->shouldBeCalled(); $form->getData()->willReturn(new \stdClass()); $event->getElement()->willReturn($element); $element->save(Argument::type('stdClass'))->shouldBeCalled(); $eventDispatcher->dispatch(FormEvents::FORM_DATA_POST_SAVE, $event)->will(function () use($event) { $event->hasResponse()->willReturn(true); $event->getResponse()->willReturn(new Response()); }); $this->handleRequest($event, $request)->shouldReturnAnInstanceOf('Symfony\\Component\\HttpFoundation\\Response'); }