/** * @param object|null $resource * * @return FormInterface */ public function getForm($resource = null) { if ($this->config->isApiRequest()) { return $this->container->get('form.factory')->createNamed('', $this->config->getFormType(), $resource); } return $this->createForm($this->config->getFormType(), $resource); }
function it_gets_form_from_class_name(Configuration $configuration, FormFactoryInterface $formFactory, FormInterface $form) { $formClass = 'spec\\Sylius\\Bundle\\ResourceBundle\\Controller\\TestFormType'; $configuration->getFormType()->willReturn($formClass); $formFactory->create(Argument::type($formClass), Argument::cetera())->shouldBeCalled()->willReturn($form); $this->getForm()->shouldReturn($form); }
/** * @param object|null $resource * * @return FormInterface */ public function getForm($resource = null) { if ($this->config->isApiRequest()) { return $this->container->get('form.factory')->createNamed('', $this->config->getFormType(), $resource); } $form = $this->config->getFormType(); if (strpos($form, '\\') !== false) { $form = new $form(); } return $this->createForm($form, $resource); }
/** * @param object|null $resource * @param array $options * * @return FormInterface */ public function getForm($resource = null, array $options = array()) { $type = $this->config->getFormType(); if (strpos($type, '\\') !== false) { // full class name specified $type = new $type(); } elseif (!$this->get('form.registry')->hasType($type)) { // form alias is not registered $defaultFormFactory = new DefaultFormFactory($this->container->get('form.factory')); return $defaultFormFactory->create($resource, $this->container->get($this->config->getServiceName('manager'))); } if ($this->config->isApiRequest()) { return $this->container->get('form.factory')->createNamed('', $type, $resource, array_merge($options, array('csrf_protection' => false))); } return $this->createForm($type, $resource, $options); }