当前位置: 首页>>代码示例>>PHP>>正文


PHP Form\FormFactoryInterface类代码示例

本文整理汇总了PHP中Symfony\Component\Form\FormFactoryInterface的典型用法代码示例。如果您正苦于以下问题:PHP FormFactoryInterface类的具体用法?PHP FormFactoryInterface怎么用?PHP FormFactoryInterface使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了FormFactoryInterface类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: setUp

 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);
 }
开发者ID:drmjo,项目名称:SonataAdminBundle,代码行数:7,代码来源:FormBuilderIteratorTest.php

示例2:

 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);
 }
开发者ID:Mangetsu,项目名称:Sylius,代码行数:7,代码来源:ResourceFormFactorySpec.php

示例3:

 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);
 }
开发者ID:Strontium-90,项目名称:Sylius,代码行数:7,代码来源:ResourceControllerSpec.php

示例4: getFormBuilder

 /**
  * {@inheritdoc}
  */
 public function getFormBuilder(FormFactoryInterface $factory)
 {
     if (!isset($this->formBuilder)) {
         $this->formBuilder = $factory->createNamedBuilder($this->getResourceProperty(), $this->getFormType(), null, $this->buildFormOptions());
     }
     return $this->formBuilder;
 }
开发者ID:norzechowicz,项目名称:resource-repository-bundle,代码行数:10,代码来源:AbstractType.php

示例5: createForm

 /**
  * @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));
 }
开发者ID:nuxia,项目名称:nuxia-plugin,代码行数:13,代码来源:FormFactory.php

示例6: switchLocaleAction

 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);
 }
开发者ID:OpenConext,项目名称:OpenConext-profile,代码行数:25,代码来源:LocaleController.php

示例7: create

 /**
  * {@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();
 }
开发者ID:Mozan,项目名称:Sylius,代码行数:10,代码来源:SettingsFormFactory.php

示例8: getForm

 /**
  * {@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;
 }
开发者ID:ashutosh-srijan,项目名称:findit_akeneo,代码行数:10,代码来源:AbstractFilter.php

示例9: getItemFormView

 /**
  * @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();
 }
开发者ID:benakacha,项目名称:Sylius,代码行数:12,代码来源:CartHelper.php

示例10: getForm

 /**
  * @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]);
 }
开发者ID:heliopsis,项目名称:ezforms-bundle,代码行数:12,代码来源:ContentRemoteIdMap.php

示例11: testSubmit

 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']);
 }
开发者ID:php-lug,项目名称:lug,代码行数:27,代码来源:TranslatableTypeTest.php

示例12: process

 /**
  *
  * @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);
 }
开发者ID:NobletSolutions,项目名称:FilteredPaginationBundle,代码行数:39,代码来源:FilteredPagination.php

示例13: createForm

 /**
  * 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;
 }
开发者ID:saberyounis,项目名称:Sonata-Project,代码行数:33,代码来源:AdminObjectAclManipulator.php

示例14: testIcon

 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']);
 }
开发者ID:php-lug,项目名称:lug,代码行数:7,代码来源:IconFormExtensionTest.php

示例15: couldBeCreatedByFormFactory

 /**
  * @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);
 }
开发者ID:DocHoncho,项目名称:PayumBundle,代码行数:10,代码来源:GatewayConfigTypeTest.php


注:本文中的Symfony\Component\Form\FormFactoryInterface类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。