public function testGetChildFormView() { $formView = new FormView(); $formView->vars['id'] = 'test'; $child = new FormView($formView); $child->vars['id'] = 'test_elementId'; $this->assertNull($this->helper->getChildFormView($formView, 'foo')); $this->isInstanceOf('Symfony\\Component\\Form\\FormView', $this->helper->getChildFormView($formView, 'test_elementId')); }
public function testGetChildFormView() { $container = $this->getMock('Symfony\\Component\\DependencyInjection\\ContainerInterface'); $pool = new Pool($container, 'title', 'logo.png'); $helper = new AdminHelper($pool); $formView = new FormView(); $formView->vars['id'] = 'test'; $child = new FormView($formView); $child->vars['id'] = 'test_elementId'; $this->assertNull($helper->getChildFormView($formView, 'foo')); $this->isInstanceOf('Symfony\\Component\\Form\\FormView', $helper->getChildFormView($formView, 'test_elementId')); }
/** * @throws NotFoundHttpException * * @param Request $request * * @return Response */ public function retrieveFormFieldElementAction(Request $request) { $code = $request->get('code'); $elementId = $request->get('elementId'); $objectId = $request->get('objectId'); $uniqid = $request->get('uniqid'); $admin = $this->pool->getInstance($code); $admin->setRequest($request); if ($uniqid) { $admin->setUniqid($uniqid); } if ($objectId) { $subject = $admin->getModelManager()->find($admin->getClass(), $objectId); if (!$subject) { throw new NotFoundHttpException(sprintf('Unable to find the object id: %s, class: %s', $objectId, $admin->getClass())); } } else { $subject = $admin->getNewInstance(); } $admin->setSubject($subject); $formBuilder = $admin->getFormBuilder($subject); $form = $formBuilder->getForm(); $form->handleRequest($request); $view = $this->helper->getChildFormView($form->createView(), $elementId); // render the widget // todo : fix this, the twig environment variable is not set inside the extension ... $extension = $this->twig->getExtension('form'); $extension->initRuntime($this->twig); $extension->renderer->setTheme($view, $admin->getFormTheme()); return new Response($extension->renderer->searchAndRenderBlock($view, 'widget')); }