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


PHP FormFactory::createBuilder方法代码示例

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


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

示例1: createFormBuilder

 /**
  * Obtains any form metadata from the entity and adds itself to the form
  * @param $entity
  * @param $form
  * @return
  */
 public function createFormBuilder($entity, $data = null, array $options = array())
 {
     // Build the $form
     $formBuilder = $this->factory->createBuilder('form', $data, $options);
     // Read the entity meta data and add to the form
     if (empty($this->drivers)) {
         return $formBuilder;
     }
     // Look to the readers to find metadata
     foreach ($this->drivers as $driver) {
         $metadata = $driver->getMetadata($entity);
         if (!empty($metadata)) {
             break;
         }
     }
     if (empty($metadata)) {
         return $formBuilder;
     }
     // Configure the form
     $fields = $metadata->getFields();
     foreach ($fields as $field) {
         // TODO: Detect "new x()" in field value or type option for AbstractType creation
         // TODO: Detect references to "%service.id%" for service constructor dependency
         $formBuilder->add($field->name, $field->value, $field->options);
     }
     return $formBuilder;
 }
开发者ID:flintlabs,项目名称:formmetadatabundle,代码行数:33,代码来源:FormMapper.php

示例2: createToggleAccessOption

 /**
  * Creates toggle access option.
  *
  * @return Form
  */
 public function createToggleAccessOption()
 {
     /** @var FormBuilder $formBuilder */
     $formBuilder = $this->formFactory->createBuilder('form');
     $form = $formBuilder->add('submit', 'submit', ['attr' => ['class' => 'btn']])->getForm();
     return $form;
 }
开发者ID:daniel-iwaniec,项目名称:ISI-PRO,代码行数:12,代码来源:ListOptionCreator.php

示例3: buildForm

 public function buildForm()
 {
     $def = $this->definitions[$this->getCurrentStep()];
     $methodName = 'build' . implode('', array_map('ucfirst', explode('-', $this->getCurrentStep()))) . 'Form';
     $builder = $this->formFactory->createBuilder('form', $this->getSubject(), array('validation_groups' => $def['validation_groups']));
     $this->{$methodName}($builder);
     $form = $builder->getForm();
     return $form;
 }
开发者ID:roomthirteen,项目名称:Room13WizardBundle,代码行数:9,代码来源:Wizard.php

示例4: registerForm

 public function registerForm(Request $request)
 {
     if ($this->pageStack->isLoggedIn()) {
         return $this->templating->renderResponse('JarvesBundle:User:logout.html.twig');
     }
     $user = new User();
     $form = $this->formFactory->createBuilder()->setData($user)->add('email', EmailType::class)->add('password', PasswordType::class)->add('save', SubmitType::class, array('label' => 'Register'))->getForm();
     $form->handleRequest($request);
     if ($form->isSubmitted() && $form->isValid()) {
     }
     return $this->templating->renderResponse('JarvesBundle:User:register.html.twig', ['form' => $form->createView()]);
 }
开发者ID:jarves,项目名称:jarves,代码行数:12,代码来源:UserLogin.php

示例5: createFormBuilder

 /**
  * Obtains any form metadata from the entity and adds itself to the form
  * @param string $data
  * @param array $options
  * @return \Symfony\Component\Form\FormBuilderInterface
  */
 public function createFormBuilder($data = null, array $options = array())
 {
     // Build the $form
     $formBuilder = $this->factory->createBuilder('form', $data, $options);
     // Read the entity meta data and add to the form
     if (empty($this->drivers)) {
         return $formBuilder;
     }
     // Look to the readers to find metadata
     foreach ($this->drivers as $driver) {
         $metadata = $driver->getMetadata($data);
         if (!empty($metadata)) {
             break;
         }
     }
     if (empty($metadata)) {
         return $formBuilder;
     }
     // Configure the form
     $fields = $metadata->getFields();
     foreach ($fields as $field) {
         // TODO: Detect "new x()" in field value or type option for AbstractType creation
         // TODO: Detect references to "%service.id%" for service constructor dependency
         $formBuilder->add($field->name, $field->value, $field->options);
     }
     $groups = $metadata->getGroups();
     foreach ($groups as $groupName => $fields) {
         $builder = $formBuilder->create($groupName, 'form', array('virtual' => true));
         foreach ($fields as $field) {
             $builder->add($field->name, $field->value, $field->options);
         }
         $formBuilder->add($builder);
     }
     $entities = $metadata->getFieldEntities();
     foreach ($entities as $entity) {
         $fieldEntityType = new FieldEntityType($entity->getClass(), $entity->getName(), $entity->getFields());
         $options = $entity->getOptions();
         if ($entity->isList()) {
             $formBuilder->add($entity->getName(), 'collection', array('type' => $fieldEntityType, 'allow_add' => true, 'allow_delete' => true, 'prototype' => true, 'options' => $entity->getOptions()));
         } else {
             $formBuilder->add($entity->getName(), $fieldEntityType, $options);
         }
     }
     $formTypes = $metadata->getFormTypes();
     foreach ($formTypes as $formType) {
         $formTypeInstance = new $formType->value();
         $formBuilder->add($formType->name, $formTypeInstance);
     }
     return $formBuilder;
 }
开发者ID:corleonis,项目名称:FormMetadataBundle,代码行数:56,代码来源:FormMapper.php

示例6: getForm

 public function getForm(Request $request, $inline = 0)
 {
     $_locale = $request->getSession()->get('sf_locale', $this->default_locale);
     $locale = new Locale();
     $locale->setLocale($_locale);
     $locale->setRedirectUrl($request->getRequestUri());
     if (!isset($this->languages[$_locale])) {
         throw new \Exception(\sprintf('invalid langauge locale: `%s` , support langages: %s ', $_locale, join(', ', array_keys($this->languages))));
     }
     $languages = $this->languages;
     if ('POST' === $request->getMethod() && $inline) {
         $languages = array($_locale => $this->languages[$_locale]);
     }
     $form = $this->form_factory->createBuilder('form', $locale, array('csrf_protection' => false))->add('locale', 'choice', array('choices' => $languages, 'attr' => array('class' => 'input-sm'), 'horizontal_input_wrapper_class' => 'sf_locale_select'))->add('redirect_url', 'hidden')->getForm();
     return $form;
 }
开发者ID:symforce,项目名称:symforce-admin,代码行数:16,代码来源:LocaleListener.php

示例7: generateForm

 public function generateForm(Entity\Test $test)
 {
     $data = array();
     $form = $this->formFactory->createBuilder();
     /** @var Entity\Question $question */
     //        foreach ($test->getQuestions() as $question) {
     //            /** @var Entity\Answer $answer */
     //            $answers = [];
     //            foreach ($question->getAnswers() as $answer) {
     ////                $form->add($question->getId(), RadioType::class, ['label' => $answer->getAnswer()]);
     //                $answers[$answer->getId()] = $answer->getAnswer();
     //            }
     //            $form->add($question->getId(), '');
     //        }
     $form->add('favorite_cities', CollectionType::class, array('entry_type' => ChoiceType::class, 'entry_options' => array('choices' => array('nashville' => 'Nashville', 'paris' => 'Paris', 'berlin' => 'Berlin', 'london' => 'London'))));
     return $form->getForm();
 }
开发者ID:dimak08,项目名称:quiz,代码行数:17,代码来源:QuizService.php

示例8: addAction

 public function addAction(Request $request)
 {
     $entry = new DiaborgEntry();
     $oldtimestamp = $request->get('oldtimestamp', null);
     if (null !== $oldtimestamp) {
         $oldtime = new DateTime();
         $oldtime->setTimestamp($oldtimestamp);
         $entry->setTimestamp($oldtime);
     }
     $form = $this->formFactory->createBuilder('form', $entry)->add('value', 'integer', array('required' => false))->add('be', 'number', array('required' => false))->add('insulin', 'number', array('required' => false))->add('timestamp', 'datetime')->add('save', 'submit')->getForm();
     $form->handleRequest($request);
     if ($form->isValid()) {
         $this->repository->addEntity($entry);
         return new RedirectResponse($this->router->generate('add', array('oldtimestamp' => $entry->getTimestamp()->getTimestamp())));
     }
     $formView = $form->createView();
     return new Response($this->templating->render('Diaborg3Bundle:Form:form3.html.twig', array('form' => $formView)));
 }
开发者ID:bestform,项目名称:diaborg3,代码行数:18,代码来源:InputController.php

示例9: createDeleteForm

 protected function createDeleteForm($id)
 {
     return $this->formFactory->createBuilder('form', ['id' => $id])->add('id', 'hidden')->getForm();
 }
开发者ID:ruslan-polutsygan,项目名称:datatable-bundle,代码行数:4,代码来源:DatatableExtension.php

示例10: buildForm

 /**
  * {@inheritdoc}
  */
 public function buildForm($data = null, array $options = [], $type = null)
 {
     $formType = is_null($type) ? $this->formType() : $type;
     $form = $this->formFactory->createBuilder($formType, $data, $options)->getForm();
     return $form;
 }
开发者ID:mikoweb,项目名称:vsymfo-core,代码行数:9,代码来源:ControllerManagerAbstract.php

示例11: getForm

 /**
  * @param $entity
  *
  * @return FormInterface
  */
 public function getForm($entity)
 {
     $form = $this->formFactory->createBuilder('form', $entity, ['csrf_protection' => false, 'dynamic_fields_disabled' => true])->getForm();
     return $form;
 }
开发者ID:Maksold,项目名称:platform,代码行数:10,代码来源:FormBuilder.php

示例12: createTrombiBlock

 public function createTrombiBlock()
 {
     $trombiFrom = $this->formFactory->createBuilder()->add('fullName', 'text', array('required' => false))->add('studentId', 'hidden', array('required' => false))->add('phoneNumber', 'hidden', array('required' => false))->add('uvs', 'hidden', array('required' => false))->add('branch', 'hidden', array('required' => false))->add('niveau', 'hidden', array('required' => false))->add('personnalMail', 'hidden', array('required' => false))->getForm();
     $block = ['template' => 'EtuCoreBundle:Main/index_blocks:trombi.html.twig', 'context' => ['trombiForm' => $trombiFrom->createView()]];
     return $block;
 }
开发者ID:ChrisdAutume,项目名称:EtuUTT,代码行数:6,代码来源:HomeRenderer.php

示例13: createForm

 /**
  * @param mixed $data
  * @param array|null $options
  *
  * @return Form
  */
 protected function createForm($data = null, array $options = null)
 {
     return $this->formFactory->createBuilder($this->formType, $data, is_array($options) ? $options : $this->defaultFormOptions)->getForm();
 }
开发者ID:mikoweb,项目名称:vsymfo-core,代码行数:10,代码来源:FormCollection.php

示例14: createFormBuilder

 /**
  * @param Module $module
  * @param array  $options
  *
  * @return \Symfony\Component\Form\FormBuilderInterface
  */
 public function createFormBuilder(Module $module, array $options = array(), $formOptions = array(), FormBuilderInterface $parentForm = null)
 {
     $modules = $this->objectManager->getRepository('BigfishEavBundle:Module')->getFields($module->getId());
     $formOptions = array_merge_recursive($formOptions, array('cascade_validation' => true, 'error_bubbling' => true, 'required' => true));
     // build new form
     /** @var $formBuilder \Symfony\Component\Form\FormBuilder **/
     $formBuilder = $parentForm ? $parentForm : $this->formFactory->createBuilder('form', null, $formOptions);
     $prepareBuilder = array();
     $sortedFields = array();
     foreach ($modules as $module) {
         foreach ($module->getField() as $field) {
             $formData = $this->fieldChain->getField($field, $module, $options);
             if ($formData) {
                 $contstraints = $this->constraintChain->getConstraints($field->getConstraints());
                 $required = false;
                 foreach ($contstraints as $constraint) {
                     if ($constraint instanceof NotBlank) {
                         $required = true;
                     }
                 }
                 $formData['formAttributes']['constraints'] = $contstraints;
                 $formData['formAttributes']['required'] = $required;
                 $sortedFields[] = $formData['identifier'];
                 $formBuilder->add($formData['identifier'], $formData['formType'], $formData['formAttributes']);
             }
         }
     }
     foreach ($formBuilder->all() as $builder) {
         $type = $builder->getType()->getName();
         if ($type == 'fieldset') {
             //                var_dump($builder->getType());
             $options = $builder->getOptions();
             $aChildFields = $options['childFields'];
             // remove unused childs and maintain order
             $newFields = array_filter($sortedFields, function ($key) use($aChildFields) {
                 return in_array($key, $aChildFields);
             });
             $subForm = array();
             foreach ($newFields as $childField) {
                 if ($formBuilder->has($childField)) {
                     if (($key = array_search($childField, $sortedFields)) !== false) {
                         unset($sortedFields[$key]);
                     }
                     //                        echo "<hr>";
                     //                        var_dump($formBuilder->get($childField)->getName());
                     //                        var_dump($formBuilder->get($childField)->getRequired());
                     //                        echo "</hr>";
                     $field = $formBuilder->get($childField);
                     $subForm[] = $field;
                     $formBuilder->remove($childField);
                 }
             }
             $elem = $formBuilder->get($builder->getName());
             $formBuilder->remove($builder->getName());
             $formBuilder->add($elem->getName(), $type, array('subforms' => $subForm, 'label' => false, 'required' => false, 'mapped' => false, 'title' => $elem->getOption('title'), 'description' => $elem->getOption('description'), 'fieldsetId' => $elem->getOption('fieldsetId')));
         }
     }
     $this->reorder($formBuilder, $sortedFields);
     // rebuild form
     foreach ($formBuilder->all() as $element) {
         if ($formBuilder->has($element->getName())) {
             $holdElement = $formBuilder->get($element->getName());
             $formBuilder->remove($element->getName());
             $formBuilder->add($holdElement);
             foreach ($holdElement->all() as $child) {
                 if ($element->has($child->getName())) {
                     $formBuilder->add($element->get($child->getName()));
                     $element->remove($child->getName());
                 }
             }
         }
     }
     return $formBuilder;
 }
开发者ID:bigfishcmf,项目名称:bigfishcmf,代码行数:80,代码来源:FormBuilder.php

示例15: buildFormFromType

 /**
  * Build the form object to return to the templating engine
  *
  * @param Type  $type
  * @param array $options
  *
  * @return FormView
  */
 public function buildFormFromType(Type $type, array $options = array())
 {
     return $this->formFactory->createBuilder($type, null, $options)->getForm()->createView();
 }
开发者ID:j7mbo,项目名称:aurex,代码行数:12,代码来源:FormFactory.php


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