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


PHP FormFactoryInterface::create方法代码示例

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


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

示例1: 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

示例2: getLocalePreferenceForm

 public function getLocalePreferenceForm($currentLocale, $route, array $routeParameters = [])
 {
     $command = new SwitchLocaleCommand();
     $command->locale = $currentLocale;
     $form = $this->formFactory->create('stepup_switch_locale', $command, ['route' => $route, 'route_parameters' => $routeParameters]);
     return $form->createView();
 }
开发者ID:surfnet,项目名称:stepup-bundle,代码行数:7,代码来源:LocaleExtension.php

示例3: 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

示例4: testSubmit

 public function testSubmit()
 {
     $form = $this->formFactory->create(get_class($this->resourceType))->submit([]);
     $this->assertSame($this->resource, $form->getConfig()->getOption('resource'));
     $this->assertSame($this->resourceFactory, $form->getConfig()->getOption('factory'));
     $form->createView();
 }
开发者ID:php-lug,项目名称:lug,代码行数:7,代码来源:AbstractResourceTypeTest.php

示例5: getForm

 public function getForm(ResourceInterface $resource)
 {
     $resourceClassName = \Doctrine\Common\Util\ClassUtils::getClass($resource);
     $resourceParts = explode("\\", $resourceClassName);
     $resourceParts[count($resourceParts) - 2] = 'Form';
     $resourceParts[count($resourceParts) - 1] .= 'Type';
     $formType = implode("\\", $resourceParts);
     if (class_exists($formType)) {
         return $this->formFactory->create(new $formType(), $resource);
     }
     $options = array('data_class' => $resourceClassName);
     $builder = $this->formFactory->createBuilder('form', $resource, $options);
     $reflectionClass = new \ReflectionClass($resourceClassName);
     $annotationClass = 'uebb\\HateoasBundle\\Annotation\\FormField';
     foreach ($reflectionClass->getProperties() as $propertyReflection) {
         /**
          * @var \uebb\HateoasBundle\Annotation\FormField $annotation
          */
         $annotation = $this->annotationReader->getPropertyAnnotation($propertyReflection, $annotationClass);
         if ($annotation) {
             $builder->add($propertyReflection->getName(), $annotation->type, is_array($annotation->options) ? $annotation->options : array());
         }
     }
     $form = $builder->getForm();
     return $form;
 }
开发者ID:uebb,项目名称:hateoas-bundle,代码行数:26,代码来源:FormResolver.php

示例6: couldBeCreatedByFormFactory

 /**
  * @test
  */
 public function couldBeCreatedByFormFactory()
 {
     $form = $this->formFactory->create(GatewayConfigType::class, null, array('data_class' => GatewayConfig::class));
     $view = $form->createView();
     $this->assertInstanceOf(FormInterface::class, $form);
     $this->assertInstanceOf(FormView::class, $view);
 }
开发者ID:Komet,项目名称:PayumBundle,代码行数:10,代码来源:GatewayConfigTypeTest.php

示例7: createForm

 /**
  * @param FormTypeInterface $type
  * @param mixed $data
  * @param array $options
  * @return FormInterface
  * @throws MissingDependencyException
  */
 public function createForm(FormTypeInterface $type, $data = null, array $options = array())
 {
     if (null === $this->formFactory) {
         throw new MissingDependencyException('No form factory present.');
     }
     return $this->formFactory->create($type, $data, $options);
 }
开发者ID:seiffert,项目名称:controller-helper-bundle,代码行数:14,代码来源:FormHelper.php

示例8: batchUpdateAction

 /**
  * @param Request $request
  *
  * @return JsonResponse
  */
 public function batchUpdateAction(Request $request)
 {
     if (!$this->isAuthorized()) {
         return new JsonResponse(null, JsonResponse::HTTP_FORBIDDEN);
     }
     $form = $this->formFactory->create(BatchType::class);
     $form->submit($this->getDataFromJsonRequest($request));
     if (!$form->isValid()) {
         $errors = $this->getErrors($form);
         return $this->createErrorResponse($errors);
     }
     $errors = [];
     $contents = [];
     foreach ($form->getData()->contents as $data) {
         $content = $this->manager->find($data->id);
         if (null === $content) {
             $errors[] = $this->createContentNotFoundError($data->id);
             continue;
         }
         $data->update($content);
         $contents[] = $content;
     }
     if (0 !== count($errors)) {
         return $this->createErrorResponse($errors);
     }
     foreach ($contents as $content) {
         $this->manager->update($content);
     }
     return new JsonResponse(null, JsonResponse::HTTP_NO_CONTENT);
 }
开发者ID:ivoaz,项目名称:content-editable-bundle,代码行数:35,代码来源:ContentController.php

示例9: 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

示例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()
 {
     $choice = new \stdClass();
     $choice->{$identifierPath = 'id'} = $id = 1;
     $choice->{$labelPath = 'label'} = $label = 'label';
     $this->resource->expects($this->once())->method('getModel')->will($this->returnValue($model = get_class($choice)));
     $this->resource->expects($this->once())->method('getIdPropertyPath')->will($this->returnValue($identifierPath));
     $this->resource->expects($this->once())->method('getLabelPropertyPath')->will($this->returnValue($labelPath));
     $this->managerRegistry->expects($this->once())->method('getManagerForClass')->with($this->identicalTo($model))->will($this->returnValue($documentManager = $this->createDocumentManagerMock()));
     $documentManager->expects($this->once())->method('getRepository')->with($this->identicalTo($model))->will($this->returnValue($repository = $this->createRepositoryMock()));
     $documentManager->expects($this->exactly(2))->method('getClassMetadata')->with($this->identicalTo($model))->will($this->returnValue($classMetadata = $this->createClassMetadataMock()));
     $classMetadata->expects($this->once())->method('getName')->will($this->returnValue($model));
     $classMetadata->expects($this->once())->method('getIdentifierFieldNames')->will($this->returnValue([$identifier = $identifierPath]));
     $classMetadata->expects($this->once())->method('getTypeOfField')->with($this->identicalTo($identifier))->will($this->returnValue('integer'));
     $repository->expects($this->once())->method('createQueryBuilder')->will($this->returnValue($queryBuilder = $this->createQueryBuilderMock($documentManager)));
     $queryBuilder->expects($this->once())->method('getQuery')->will($this->returnValue($query = $this->createQueryMock()));
     $query->expects($this->once())->method('execute')->will($this->returnValue($iterator = $this->createIteratorMock()));
     $iterator->expects($this->once())->method('toArray')->will($this->returnValue([$choice]));
     $form = $this->factory->create(ResourceChoiceType::class, null, ['resource' => $this->resource])->submit($id);
     $this->assertSame($this->resource, $form->getConfig()->getOption('resource'));
     $this->assertSame($identifierPath, $form->getConfig()->getOption('choice_value'));
     $this->assertSame($labelPath, $form->getConfig()->getOption('choice_label'));
     $this->assertSame('', $form->getConfig()->getOption('placeholder'));
     $this->assertSame($choice, $form->getData());
     $form->createView();
 }
开发者ID:php-lug,项目名称:lug,代码行数:26,代码来源:ResourceChoiceTypeTest.php

示例12: couldBeCreatedByFormFactory

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

示例13: testLabelAdd

 public function testLabelAdd()
 {
     $form = $this->factory->create(CollectionType::class, [], ['allow_add' => true, 'label_add' => $label = 'foo'])->submit([]);
     $view = $form->createView();
     $this->assertArrayHasKey('label_add', $view->vars);
     $this->assertSame($label, $view->vars['label_add']);
 }
开发者ID:php-lug,项目名称:lug,代码行数:7,代码来源:CollectionExtensionTest.php

示例14: handle

 /**
  * {@inheritdoc}
  */
 public function handle(Request $request, FormHandlerInterface $handler, FormInterface $form = null)
 {
     if (null !== $form) {
         $handler->setForm($form);
     } elseif (null === ($form = $handler->getForm())) {
         if ($handler instanceof NamedFormHandlerInterface && null !== ($name = $handler->getName())) {
             $form = $this->form_factory->createNamed($name, $handler->getType(), $handler->getData(), $handler->getOptions());
         } else {
             $form = $this->form_factory->create($handler->getType(), $handler->getData(), $handler->getOptions());
         }
         if (!$form instanceof FormInterface) {
             throw new FormNotFoundException($handler);
         }
         // set the form which is associated with the handler
         $handler->setForm($form);
     }
     $form->handleRequest($request);
     if (!$form->isSubmitted()) {
         return null;
     }
     if ($form->isValid()) {
         if ($handler instanceof FormSuccessHandlerInterface) {
             return $handler->onSuccess($request);
         }
     } elseif ($handler instanceof FormFailureHandlerInterface) {
         return $handler->onFailure($request);
     }
 }
开发者ID:hostnet,项目名称:form-handler-component,代码行数:31,代码来源:SimpleFormProvider.php

示例15: 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


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