php Symfony-Component-Form-FormFactoryInterface类(方法)实例源码

下面列出了php Symfony-Component-Form-FormFactoryInterface 类(方法)源码代码实例,从而了解它的用法。

作者:drmj    项目:SonataAdminBundl   
protected function setUp()
 {
     $this->dispatcher = $this->getMock('Symfony\\Component\\EventDispatcher\\EventDispatcherInterface');
     $this->factory = $this->getMock('Symfony\\Component\\Form\\FormFactoryInterface');
     $this->builder = new TestFormBuilder('name', null, $this->dispatcher, $this->factory);
     $this->factory->expects($this->any())->method('createNamedBuilder')->willReturn($this->builder);
 }

作者:Mangets    项目:Syliu   
function it_creates_the_object_if_form_is_a_class_name(RequestConfiguration $requestConfiguration, ResourceInterface $resource, FormFactoryInterface $formFactory, FormInterface $form)
 {
     $requestConfiguration->isHtmlRequest()->willReturn(true);
     $requestConfiguration->getFormType()->willReturn(TextType::class);
     $formFactory->create(Argument::type(TextType::class), $resource)->willReturn($form);
     $this->create($requestConfiguration, $resource)->shouldReturn($form);
 }

作者:Strontium-9    项目:Syliu   
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);
 }

作者:norzechowic    项目:resource-repository-bundl   
/**
  * {@inheritdoc}
  */
 public function getFormBuilder(FormFactoryInterface $factory)
 {
     if (!isset($this->formBuilder)) {
         $this->formBuilder = $factory->createNamedBuilder($this->getResourceProperty(), $this->getFormType(), null, $this->buildFormOptions());
     }
     return $this->formBuilder;
 }

作者:nuxi    项目:nuxia-plugi   
/**
  * @param mixed|null $data
  * @param array      $options
  *
  * @return \Symfony\Component\Form\FormInterface
  */
 public function createForm($data = null, array $options = [])
 {
     if ($data != null) {
         $this->setData($data);
     }
     return $this->formFactory->create($this->type, null, array_merge($this->options, $options));
 }

作者:OpenConex    项目:OpenConext-profil   
public function switchLocaleAction(Request $request)
 {
     $this->guard->userIsLoggedIn();
     $this->logger->notice('User requested to switch locale');
     $returnUrl = $request->query->get('return-url');
     // Return URLs generated by us always include a path (ie. at least a forward slash)
     // @see https://github.com/symfony/symfony/blob/master/src/Symfony/Component/HttpFoundation/Request.php#L878
     $domain = $request->getSchemeAndHttpHost() . '/';
     if (strpos($returnUrl, $domain) !== 0) {
         $this->logger->error(sprintf('Illegal return-url ("%s") for redirection after changing locale, aborting request', $returnUrl));
         throw new BadRequestHttpException('Invalid return-url given');
     }
     $command = new ChangeLocaleCommand();
     $form = $this->formFactory->create('profile_switch_locale', $command, [])->handleRequest($request);
     $this->logger->notice(sprintf('Switching locale from "%s" to "%s"', $request->getLocale(), $command->newLocale));
     if ($form->isValid()) {
         $this->userService->changeLocale($command);
         $this->flashBag->add('success', 'profile.locale.locale_change_success');
         $this->logger->notice(sprintf('Successfully switched locale from "%s" to "%s"', $request->getLocale(), $command->newLocale));
     } else {
         $this->flashBag->add('error', 'profile.locale.locale_change_fail');
         $this->logger->error('Locale not switched: the switch locale form contained invalid data');
     }
     return new RedirectResponse($returnUrl);
 }

作者:Moza    项目:Syliu   
/**
  * {@inheritdoc}
  */
 public function create($namespace, $data = null, array $options = [])
 {
     $schema = $this->schemaRegistry->getSchema($namespace);
     $builder = $this->formFactory->createBuilder('form', $data, array_merge_recursive(['data_class' => null], $options));
     $schema->buildForm($builder);
     return $builder->getForm();
 }

作者:ashutosh-srija    项目:findit_akene   
/**
  * {@inheritDoc}
  */
 public function getForm()
 {
     if (!$this->form) {
         $this->form = $this->formFactory->create($this->getFormType(), [], array_merge($this->getOr(FilterUtility::FORM_OPTIONS_KEY, []), ['csrf_protection' => false]));
     }
     return $this->form;
 }

作者:benakach    项目:Syliu   
/**
  * @param array $options
  *
  * @return FormView
  */
 public function getItemFormView(array $options = array())
 {
     $cartItem = $this->cartItemFactory->createNew();
     $this->orderItemQuantityModifier->modify($cartItem, 1);
     $form = $this->formFactory->create('sylius_cart_item', $cartItem, $options);
     return $form->createView();
 }

作者:heliopsi    项目:ezforms-bundl   
/**
  * @param Location $location
  * @return \Symfony\Component\Form\FormInterface
  * @throws \Heliopsis\eZFormsBundle\Exceptions\UnknownFormException
  */
 public function getForm(Location $location)
 {
     if (!isset($this->map[$location->contentInfo->remoteId])) {
         throw new UnknownFormException(sprintf("No form could be mapped to content remote id %s", $location->contentInfo->remoteId));
     }
     return $this->formFactory->create($this->map[$location->contentInfo->remoteId]);
 }

作者:php-lu    项目:lu   
public function testSubmit()
 {
     $this->translatableResource->expects($this->once())->method('getModel')->will($this->returnValue(TranslatableTest::class));
     $this->translatableResource->expects($this->once())->method('getRelation')->with($this->identicalTo('translation'))->will($this->returnValue($translationResource = $this->createResourceMock()));
     $translationResource->expects($this->once())->method('getForm')->will($this->returnValue(TranslationTestType::class));
     $this->translatableFactory->expects($this->once())->method('create')->will($this->returnValue(new TranslatableTest()));
     $form = $this->formFactory->create(TranslatableTestType::class)->submit(['translations' => ['en' => ['value' => 'value-en'], 'fr' => ['value' => 'value-fr']]]);
     $translatable = $form->getData();
     $view = $form->createView();
     $this->assertInstanceOf(TranslatableTest::class, $translatable);
     $this->assertCount(1, $view->children);
     $this->assertArrayHasKey('translations', $view->children);
     $this->assertCount(2, $translatable->getTranslations());
     $this->assertTrue($translatable->getTranslations()->containsKey('en'));
     $this->assertTrue($translatable->getTranslations()->containsKey('fr'));
     $this->assertCount(2, $view->children['translations']);
     $this->assertArrayHasKey('en', $view->children['translations']);
     $this->assertArrayHasKey('fr', $view->children['translations']);
     $this->assertInstanceOf(TranslationTest::class, $translatable->getTranslations()['en']);
     $this->assertSame('value-en', $translatable->getTranslations()['en']->getValue());
     $this->assertCount(1, $view->children['translations']['en']);
     $this->assertArrayHasKey('value', $view->children['translations']['en']);
     $this->assertInstanceOf(TranslationTest::class, $translatable->getTranslations()['fr']);
     $this->assertSame('value-fr', $translatable->getTranslations()['fr']->getValue());
     $this->assertCount(1, $view->children['translations']['fr']);
     $this->assertArrayHasKey('value', $view->children['translations']['fr']);
 }

作者:NobletSolution    项目:FilteredPaginationBundl   
/**
  *
  * @param Request $request
  * @param AbstractType|string $formType
  * @param Query $query
  * @param string $sessionKey
  * @param array $formOptions
  * @return array
  */
 public function process(Request $request, $formType, $query, $sessionKey, array $formOptions = array())
 {
     $filterForm = $this->formFactory->create($formType, null, $formOptions);
     $method = $filterForm->getConfig()->getMethod();
     $requestData = $method == 'GET' ? $request->query->get($filterForm->getName()) : $request->request->get($filterForm->getName());
     if (isset($requestData['reset'])) {
         if ($method == 'POST') {
             $request->getSession()->remove($sessionKey);
             return array($filterForm, null, true);
         }
         $request->getSession()->set($sessionKey, array());
         $requestData = array();
     }
     $filterData = empty($requestData) ? $request->getSession()->get($sessionKey, $requestData) : $requestData;
     if (!empty($filterData)) {
         $this->applyFilter($filterForm, $filterData, $query);
         if (empty($filterData)) {
             $request->getSession()->remove($sessionKey);
         } else {
             $request->getSession()->set($sessionKey, $filterData);
         }
     }
     $this->updatePerPage($request, $sessionKey);
     $page = $request->query->get($this->knpParams['pageParameterName'], 1);
     $event = $this->eventDispatcher->dispatch(FilterEvent::POST_FILTER, new FilterEvent($query));
     if ($event->hasNewQuery()) {
         $query = $event->getNewQuery();
     }
     return array($filterForm, $this->paginator->paginate($query, $page, $this->perPage, $this->knpParams), false);
 }

作者:saberyouni    项目:Sonata-Projec   
/**
  * Gets the form
  *
  * @param  \Sonata\AdminBundle\Util\AdminObjectAclData $data
  * @return \Symfony\Component\Form\Form
  */
 public function createForm(AdminObjectAclData $data)
 {
     // Retrieve object identity
     $objectIdentity = ObjectIdentity::fromDomainObject($data->getObject());
     $acl = $data->getSecurityHandler()->getObjectAcl($objectIdentity);
     if (!$acl) {
         $acl = $data->getSecurityHandler()->createAcl($objectIdentity);
     }
     $data->setAcl($acl);
     $masks = $data->getMasks();
     // Create a form to set ACL
     $formBuilder = $this->formFactory->createBuilder('form');
     foreach ($data->getAclUsers() as $aclUser) {
         $securityIdentity = UserSecurityIdentity::fromAccount($aclUser);
         foreach ($data->getUserPermissions() as $permission) {
             try {
                 $checked = $acl->isGranted(array($masks[$permission]), array($securityIdentity));
             } catch (NoAceFoundException $e) {
                 $checked = false;
             }
             $formBuilder->add($aclUser->getId() . $permission, 'checkbox', array('required' => false, 'data' => $checked));
         }
     }
     $form = $formBuilder->getForm();
     $data->setForm($form);
     return $form;
 }

作者:php-lu    项目:lu   
public function testIcon()
 {
     $form = $this->factory->create(FormType::class, null, ['icon' => $icon = 'my.icon']);
     $view = $form->createView();
     $this->assertArrayHasKey('icon', $view->vars);
     $this->assertSame($icon, $view->vars['icon']);
 }

作者:DocHonch    项目:PayumBundl   
/**
  * @test
  */
 public function couldBeCreatedByFormFactory()
 {
     $form = $this->formFactory->create('payum_gateway_config', null, array('data_class' => 'Payum\\Core\\Model\\GatewayConfig'));
     $view = $form->createView();
     $this->assertInstanceOf('Symfony\\Component\\Form\\FormInterface', $form);
     $this->assertInstanceOf('Symfony\\Component\\Form\\FormView', $view);
 }

作者:php-lu    项目:lu   
public function testLabelTranslationArguments()
 {
     $form = $this->factory->create(ButtonType::class, null, ['label_translation_arguments' => $arguments = ['foo' => 'bar']]);
     $view = $form->createView();
     $this->assertArrayHasKey('label_translation_arguments', $view->vars);
     $this->assertSame($arguments, $view->vars['label_translation_arguments']);
 }

作者:Kome    项目:PayumBundl   
/**
  * @test
  */
 public function couldBeCreatedByFormFactory()
 {
     $form = $this->formFactory->create(GatewayFactoriesChoiceType::class);
     $view = $form->createView();
     $this->assertInstanceOf(FormInterface::class, $form);
     $this->assertInstanceOf(FormView::class, $view);
 }

作者:bcreme    项目:Syliu   
/**
  * {@inheritdoc}
  */
 public function create($namespace)
 {
     $schema = $this->schemaRegistry->getSchema($namespace);
     $builder = $this->formFactory->createBuilder('form', null, array('data_class' => null));
     $schema->buildForm($builder);
     return $builder->getForm();
 }

作者:DocHonch    项目:PayumBundl   
/**
  * @test
  */
 public function couldBeCreatedByFormFactory()
 {
     $form = $this->formFactory->create('payum_gateway_factories_choice');
     $view = $form->createView();
     $this->assertInstanceOf('Symfony\\Component\\Form\\FormInterface', $form);
     $this->assertInstanceOf('Symfony\\Component\\Form\\FormView', $view);
 }

作者:tentwofou    项目:sf2-for   
public function testSetInvalidYearsOption()
 {
     $help = 'Having trouble with the internets? Tell us about it.';
     $form = $this->factory->createNamed('__test___field', $this->getTestedType(), null, ['help' => $help]);
     $view = $form->createView();
     $this->assertSame($help, $view->vars['help']);
 }


问题


面经


文章

微信
公众号

扫码关注公众号