Creates and returns a form builder instance.
protected createFormBuilder ( mixed $data = null, array $options = [] ) : |
||
$data | mixed | The initial data for the form |
$options | array | Options for the form |
return |
public function onController(Controller $controller, Request $request) { $object = $this->admin->newObject(); $label = null; if ($this->admin->tree && $this->admin->getTreeObjectId()) { $label = $this->admin->trans('sf.tree.create.title', array('%object%' => $this->admin->string($this->admin->getTreeObject()), '%admin%' => $this->admin->getLabel()), $this->sf_domain); } else { $label = $this->admin->getFormLabel(); } $list_url = $this->admin->path('list'); $this->admin->setFormOriginalObject($object); $builder = $controller->createFormBuilder($object, array('label' => $label)); $this->admin->buildCreateForm($controller, $object, $builder, $this); $this->buildFormReferer($request, $builder, $object, $list_url); $form = $builder->getForm(); $this->setForm($form); $dispatcher = $this->admin->getService('event_dispatcher'); $event = new \Symforce\AdminBundle\Event\FormEvent($form, $request); $dispatcher->dispatch('sf.event.form', $event); if (null !== $event->getResponse()) { return $event->getResponse(); } if ($request->isMethod('POST')) { $form->handleRequest($request); $this->admin->fireEvent('submit', $form); if ($form->isValid()) { $this->admin->onUpdate($controller, $request, $this, $object, $form); if ($form->isValid()) { $this->admin->update($object); return $this->admin->afterUpdate($controller, $request, $this, $object, $form); } } } return $controller->render($this->template, array('sf_admin_loader' => $controller->get('sf.admin.loader'), 'admin' => $this->admin, 'action' => $this, 'form' => $form->createView())); }
/** * creates form builder with iframe params * @see generateAppUrl * @param null $data * @param array $options * @return \Symfony\Component\Form\FormBuilder */ public function createFormBuilder($data = null, array $options = array()) { $builder = parent::createFormBuilder($data, $options); /** * @var $urlBuilder Url */ $urlBuilder = $this->get('dream_commerce_shop_appstore.url'); $listener = new AppFormListener($urlBuilder, $builder); $builder->addEventListener(FormEvents::PRE_SUBMIT, array($listener, 'appendValidationTokens')); return $builder; }
public function onController(Controller $controller, Request $request) { $object_id = (int) $this->admin->getRouteObjectId(); $page_object = null; if ($object_id) { $object = $this->admin->getRouteObject(); $page_object = $this->admin->getPageObject($object); } else { $object = null; $page_object = $this->admin->getRootPageObject(); } $page_admin = $this->admin->getPageAdmin(); $this->admin->setFormOriginalObject($object); $builder = $controller->createFormBuilder($page_object, array('label' => $this->admin->getFormLabel())); $list_url = $this->admin->path('list'); $update_action = $page_admin->getAction('update'); $page_admin->buildUpdateForm($controller, $page_object, $builder, $update_action); $this->buildFormReferer($request, $builder, $object, $list_url); $form = $builder->getForm(); $this->setForm($form); $dispatcher = $this->admin->getService('event_dispatcher'); $event = new \Symforce\AdminBundle\Event\FormEvent($form, $request); $dispatcher->dispatch('sf.event.form', $event); if (null !== $event->getResponse()) { return $event->getResponse(); } if ($request->isMethod('POST')) { $form->bind($request); $this->admin->fireEvent('submit', $form); if ($form->isValid()) { $page_admin->onUpdate($controller, $request, $update_action, $page_object, $form); if ($form->isValid()) { $em = $this->admin->getManager(); $uow = $em->getUnitOfWork(); if ($object) { // need copy propertie back to object , $this->admin->update($object); } else { $page_admin->update($page_object); } $request->getSession()->getFlashBag()->add('info', $this->trans('sf.action.update.finish', $object)); return $controller->redirect($this->getFormReferer($form)); } } } return $controller->render($this->template, array('sf_admin_loader' => $controller->get('sf.admin.loader'), 'admin' => $this->admin, 'page_admin' => $page_admin, 'action' => $this, 'object' => $object, 'form' => $form->createView())); }
public function onController(Controller $controller, Request $request) { $object = $this->admin->getRouteObject(); $list_url = $this->admin->path('list'); if (!$object) { $request->getSession()->getFlashBag()->add('error', 'not exists!'); return $controller->redirect($list_url); } /* $tr = $controller->get('translator') ; */ $this->admin->setFormOriginalObject($object); $builder = $controller->createFormBuilder($object, array('label' => $this->admin->getFormLabel())); $this->admin->buildUpdateForm($controller, $object, $builder, $this); $this->buildFormReferer($request, $builder, $object, $list_url); $form = $builder->getForm(); $this->setForm($form); $dispatcher = $this->admin->getService('event_dispatcher'); $event = new \Symforce\AdminBundle\Event\FormEvent($form, $request); $dispatcher->dispatch('sf.event.form', $event); if (null !== $event->getResponse()) { return $event->getResponse(); } if ($request->isMethod('POST')) { $form->bind($request); $this->admin->fireEvent('submit', $form); if ($form->isValid()) { $this->admin->onUpdate($controller, $request, $this, $object, $form); if ($form->isValid()) { $this->admin->update($object); return $this->admin->afterUpdate($controller, $request, $this, $object, $form); } } } return $controller->render($this->template, array('sf_admin_loader' => $controller->get('sf.admin.loader'), 'admin' => $this->admin, 'action' => $this, 'form' => $form->createView())); }
public function testCreateFormBuilder() { $formBuilder = $this->getMock('Symfony\\Component\\Form\\FormBuilderInterface'); $formFactory = $this->getMock('Symfony\\Component\\Form\\FormFactoryInterface'); $formFactory->expects($this->once())->method('createBuilder')->willReturn($formBuilder); $container = $this->getMock('Symfony\\Component\\DependencyInjection\\ContainerInterface'); $container->expects($this->at(0))->method('get')->will($this->returnValue($formFactory)); $controller = new Controller(); $controller->setContainer($container); $this->assertEquals($formBuilder, $controller->createFormBuilder('foo')); }
/** * {@inheritdoc} */ public function createFormBuilder($data = null, array $options = array()) { $this->checkCsrf($options); return parent::createFormBuilder($data, $options); }
public function createFormBuilder($data = null, array $options = array()) { return parent::createFormBuilder($data, $options); }
public function onController(Controller $controller, Request $request) { $object = $this->admin->getRouteObject(); $list_url = $this->admin->path('list'); if (!$object) { $request->getSession()->getFlashBag()->add('error', 'not exists!'); return $controller->redirect($this->admin->path('list')); } $admin_children = array(); $children = $this->admin->getAdminRouteChildren(); if ($children) { foreach ($children as $child_admin_name => $o) { if ($o[0]) { throw new \Exception("unimplement"); } $admin_children[$child_admin_name] = array(); $child_admin = $this->admin->getAdminLoader()->getAdminByName($child_admin_name); $properties = $o[0] ? $o[1] : array($o[1]); foreach ($properties as $config) { $child_property = $config[0]; $my_property = $config[1]; $count = $child_admin->countBy($child_property, $object); $admin_children[$child_admin_name][$child_property] = $count; } } } /** * @var \Symfony\Component\Form\FormBuilder */ $builder = $controller->createFormBuilder($object, array('label' => $this->admin->getFormLabel(), 'constraints' => array(new \Symfony\Component\Validator\Constraints\Callback(function ($object, \Symfony\Component\Validator\Context\ExecutionContext $context) use($controller, $admin_children) { foreach ($admin_children as $child_admin_name => $list) { $child_admin = $this->admin->getAdminLoader()->getAdminByName($child_admin_name); foreach ($list as $count) { if ($count > 0) { if (!$child_admin->auth('delete')) { $error = $this->admin->trans('sf.action.delete.error.child', array('%admin%' => $this->admin->getLabel(), '%child%' => $child_admin->getLabel(), '%count%' => $count), $this->sf_domain); $context->addViolation($error); } } } } })))); $this->buildFormReferer($request, $builder, $object, $list_url); $form = $builder->getForm(); $this->setForm($form); $dispatcher = $this->admin->getService('event_dispatcher'); $event = new \Symforce\AdminBundle\Event\FormEvent($form, $request); $dispatcher->dispatch('sf.event.form', $event); if (null !== $event->getResponse()) { return $event->getResponse(); } if ($request->isMethod('POST')) { $form->bind($request); $this->admin->fireEvent('submit', $form); if ($form->isValid()) { $msg = $this->trans('sf.action.delete.finish', $object); $this->admin->remove($object); $request->getSession()->getFlashBag()->add('info', $msg); return $controller->redirect($this->getFormReferer($form)); } } return $controller->render($this->template, array('sf_admin_loader' => $controller->get('sf.admin.loader'), 'admin' => $this->admin, 'action' => $this, 'form' => $form->createView())); }