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


PHP FormFactoryInterface::createBuilder方法代码示例

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


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

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

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

示例3: getFormBuilder

 /**
  * @return FormBuilderInterface
  */
 protected function getFormBuilder()
 {
     if (!$this->formBuilder) {
         $this->formBuilder = $this->formFactory->createBuilder($this->getFormType(), [], array_merge($this->getOr(FilterUtility::FORM_OPTIONS_KEY, []), ['csrf_protection' => false]));
     }
     return $this->formBuilder;
 }
开发者ID:aml-bendall,项目名称:ExpandAkeneoApi,代码行数:10,代码来源:AbstractFilter.php

示例4: invoke

 public function invoke(Request $request)
 {
     $type = new LoginFormType($request);
     $builder = $this->formFactory->createBuilder($type, [], ['action' => $this->checkPath]);
     $form = $builder->getForm();
     return ['form' => $form->createView()];
 }
开发者ID:mikegibson,项目名称:sentient,代码行数:7,代码来源:LoginAction.php

示例5: contactAction

 /**
  * @Route("/contact", name="contact_route")
  * @param Request $request
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function contactAction(Request $request)
 {
     /** @var AnonymousToken $token */
     $token = $this->tokenStorage->getToken();
     /** @var User $user */
     $user = $token->getUser();
     $contact = new Contact();
     if ($user !== 'anon.') {
         /** @var User $user */
         $contact->setEmail($user->getEmail());
         $contact->setUser($user);
     }
     $emailGetParam = $request->query->get('email');
     if (!empty($emailGetParam)) {
         $contact->setEmail($emailGetParam);
     }
     $form = $this->formFactory->createBuilder(FormType::class, $contact)->add('email', TextType::class, ['attr' => ['placeholder' => 'votre@adresse.email']])->add('message', TextareaType::class, ['attr' => ['maxlength' => 1000, 'rows' => 10]])->add('submit', SubmitType::class, ['label' => 'Envoyer'])->getForm();
     $form->handleRequest($request);
     if ($form->isValid()) {
         $this->contactService->record($contact);
         $this->session->getFlashBag()->add(static::FLASH_BAG_EMAIL, $contact->getEmail());
         return new RedirectResponse($this->router->generate('confirmation_contact_route'));
     } else {
         return new Response($this->templating->render('base.html.twig', [TwigNodeTemplateTreeSection::TEMPLATE_TREE_BRANCH => 'contact', 'form' => $form->createView()]), $form->isSubmitted() ? Response::HTTP_BAD_REQUEST : Response::HTTP_OK);
     }
 }
开发者ID:apflieger,项目名称:zigotoo,代码行数:31,代码来源:ContactController.php

示例6: create

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

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

示例8: build

 public function build(GenericResourceElement $element)
 {
     $resources = $this->getResourceGroup($element->getKey());
     $builder = $this->formFactory->createBuilder('form', $this->createFormData($element, $element->getRepository(), $resources), $element->getResourceFormOptions());
     $this->buildForm($element, $builder, $resources);
     return $builder->getForm();
 }
开发者ID:kbedn,项目名称:admin-bundle,代码行数:7,代码来源:ResourceFormBuilder.php

示例9: create

 /**
  * {@inheritdoc}
  */
 public function create($schemaAlias, $data = null, array $options = [])
 {
     /** @var SchemaInterface $schema */
     $schema = $this->schemaRegistry->get($schemaAlias);
     $builder = $this->formFactory->createBuilder('form', $data, array_merge_recursive(['data_class' => null], $options));
     $schema->buildForm($builder);
     return $builder->getForm();
 }
开发者ID:ReissClothing,项目名称:Sylius,代码行数:11,代码来源:SettingsFormFactory.php

示例10: createForm

 /**
  * Creates a form
  *
  * @param CategoryInterface $category
  *
  * @return Form
  */
 public function createForm(CategoryInterface $category)
 {
     $topic = new $this->modelClass();
     $topic->setCategory($category);
     $topic->setUser($this->getAuthenticatedUser());
     $builder = $this->formFactory->createBuilder($this->type, $topic);
     return $builder->getForm();
 }
开发者ID:qushe-demon,项目名称:ghost,代码行数:15,代码来源:NewTopicFormFactory.php

示例11: createForm

 /**
  * Creates a form
  *
  * @param TopicInterface $topic
  *
  * @return Form
  */
 public function createForm(TopicInterface $topic)
 {
     $post = new $this->modelClass();
     $post->setTopic($topic);
     $post->setUser($this->getAuthenticatedUser());
     $builder = $this->formFactory->createBuilder($this->type, $post);
     return $builder->getForm();
 }
开发者ID:qushe-demon,项目名称:ghost,代码行数:15,代码来源:NewPostFormFactory.php

示例12: testLabelPrefix

 public function testLabelPrefix()
 {
     $form = $this->factory->createBuilder(FormType::class, null, ['label_prefix' => $labelPrefix = 'prefix'])->add($buttonName = 'button', ButtonType::class)->getForm();
     $view = $form->createView();
     $buttonView = $view->children[$buttonName];
     $this->assertArrayHasKey('label', $buttonView->vars);
     $this->assertSame($labelPrefix . '.' . $buttonName, $buttonView->vars['label']);
 }
开发者ID:php-lug,项目名称:lug,代码行数:8,代码来源:LabelButtonExtensionTest.php

示例13: createForm

 /**
  * {@inheritdoc}
  */
 public function createForm(array $options)
 {
     $builder = $this->formFactory->createBuilder($this->type, $this->entity, $options);
     if ($this->action !== null) {
         $builder->setAction($this->action);
     }
     $this->form = $builder->getForm();
     return $this->form;
 }
开发者ID:bolt,项目名称:Members,代码行数:12,代码来源:AbstractFormBuilder.php

示例14: buildForm

 /**
  * @return FormInterface
  */
 public function buildForm()
 {
     $builder = $this->formFactory->createBuilder('form', null);
     foreach ($this->tabs as $tab) {
         $tab->buildForm($builder);
     }
     $this->form = $builder->getForm();
     return $this->form;
 }
开发者ID:BranchBit,项目名称:KunstmaanBundlesCMS,代码行数:12,代码来源:TabPane.php

示例15: buildForm

 /**
  * @return FormInterface
  */
 public function buildForm()
 {
     $builder = $this->formFactory->createBuilder('form', null, array('cascade_validation' => true));
     foreach ($this->tabs as $tab) {
         $tab->buildForm($builder);
     }
     $this->form = $builder->getForm();
     return $this->form;
 }
开发者ID:headonkeyboard,项目名称:KunstmaanBundlesCMS,代码行数:12,代码来源:TabPane.php


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