當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Form\FormFactory類代碼示例

本文整理匯總了PHP中Symfony\Component\Form\FormFactory的典型用法代碼示例。如果您正苦於以下問題:PHP FormFactory類的具體用法?PHP FormFactory怎麽用?PHP FormFactory使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了FormFactory類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: createForm

 /**
  * @param object                              $entity
  * @param \Symfony\Component\Form\FormFactory $formFactory
  * @param null                                $action
  * @param array                               $options
  *
  * @return \Symfony\Component\Form\FormInterface
  */
 public function createForm($entity, $formFactory, $action = null, $options = [])
 {
     $fields = $this->leadFieldModel->getFieldListWithProperties();
     $choices = [];
     foreach ($fields as $alias => $field) {
         if (!isset($choices[$field['group_label']])) {
             $choices[$field['group_label']] = [];
         }
         $choices[$field['group_label']][$alias] = $field['label'];
     }
     // Only show the lead fields not already used
     $usedLeadFields = $this->session->get('mautic.form.' . $entity['formId'] . '.fields.leadfields', []);
     $testLeadFields = array_flip($usedLeadFields);
     $currentLeadField = isset($entity['leadField']) ? $entity['leadField'] : null;
     if (!empty($currentLeadField) && isset($testLeadFields[$currentLeadField])) {
         unset($testLeadFields[$currentLeadField]);
     }
     foreach ($choices as &$group) {
         $group = array_diff_key($group, $testLeadFields);
     }
     $options['leadFields'] = $choices;
     $options['leadFieldProperties'] = $fields;
     if ($action) {
         $options['action'] = $action;
     }
     return $formFactory->create('formfield', $entity, $options);
 }
開發者ID:dongilbert,項目名稱:mautic,代碼行數:35,代碼來源:FieldModel.php

示例2: array

 function it_returns_form_builder_with_additional_file_options_and_file_constraints(FormFactory $factory, FormBuilder $form, NotBlank $constraint)
 {
     $this->addConstraint($constraint);
     $this->setFormOptions(array('file_type' => 'fsi_image', 'file_options' => array('file_option' => 'value')));
     $factory->createNamedBuilder('fileValue', 'fsi_removable_file', null, array('label' => false, 'required' => false, 'file_type' => 'fsi_image', 'file_options' => array('file_option' => 'value', 'constraints' => array($constraint))))->shouldBeCalled()->willReturn($form);
     $this->getFormBuilder($factory)->shouldReturn($form);
 }
開發者ID:norzechowicz,項目名稱:resource-repository-bundle,代碼行數:7,代碼來源:FSiRemovableFileTypeSpec.php

示例3: createForm

 /**
  * {@inheritdoc}
  *
  * @param object                              $entity
  * @param \Symfony\Component\Form\FormFactory $formFactory
  * @param null                                $action
  * @param array                               $options
  *
  * @throws NotFoundHttpException
  */
 public function createForm($entity, $formFactory, $action = null, $options = [])
 {
     if (!$entity instanceof Focus) {
         throw new MethodNotAllowedHttpException(['Focus']);
     }
     if (!empty($action)) {
         $options['action'] = $action;
     }
     return $formFactory->create('focus', $entity, $options);
 }
開發者ID:dongilbert,項目名稱:mautic,代碼行數:20,代碼來源:FocusModel.php

示例4: resolveItemToAdd

 /**
  * {@inheritdoc}
  */
 public function resolveItemToAdd(Request $request)
 {
     /*
      * We're getting here product set id via query but you can easily override route
      * pattern and use attributes, which are available through request object.
      */
     if ($id = $request->query->get('id')) {
         if ($product_set = $this->productSetManager->findSet($id)) {
             /*
              * To have it flexible, we allow adding single item by GET request
              * and also user can provide desired quantity by form via POST request.
              */
             $item = $this->itemManager->createItem();
             $item->setProductSet($product_set);
             if ('POST' === $request->getMethod()) {
                 $form = $this->formFactory->create('chewbacca_cart_item');
                 $form->setData($item);
                 $form->bindRequest($request);
                 if (!$form->isValid()) {
                     return false;
                 }
             }
             return $item;
         }
     }
 }
開發者ID:hd-deman,項目名稱:Chewbacca,代碼行數:29,代碼來源:ItemResolver.php

示例5: postGameAction

 public function postGameAction(Request $request)
 {
     $uuid = $this->uuidGenerator->generate();
     $gameStartCommand = new GameStartCommand($uuid, "hup");
     $form = $this->formFactory->create(new GameStartType(), $gameStartCommand);
     $this->handleForm($request, $form, $uuid, $gameStartCommand);
 }
開發者ID:weemen,項目名稱:hangman_lennard,代碼行數:7,代碼來源:DefaultController.php

示例6: boxAction

 /**
  * @Template(":Todo/Search:box.html.twig")
  * @return array
  */
 public function boxAction(Request $request)
 {
     $search = new TodoList();
     $form = $this->formFactory->create('todo_list', $search);
     $form->handleRequest($request);
     return ['form' => $form->createView()];
 }
開發者ID:polidog,項目名稱:symfony_sample_todo,代碼行數:11,代碼來源:SearchController.php

示例7: process

 /**
  * Process form
  *
  * @param  Call $entity
  *
  * @return bool  True on successful processing, false otherwise
  */
 public function process(Call $entity)
 {
     $targetEntityClass = $this->request->get('entityClass');
     $targetEntityId = $this->request->get('entityId');
     $options = [];
     if ($targetEntityClass && $this->request->getMethod() === 'GET') {
         $targetEntity = $this->entityRoutingHelper->getEntity($targetEntityClass, $targetEntityId);
         if (!$entity->getId()) {
             $entity->setPhoneNumber($this->phoneProvider->getPhoneNumber($targetEntity));
         }
         $options = ['phone_suggestions' => array_unique(array_map(function ($item) {
             return $item[0];
         }, $this->phoneProvider->getPhoneNumbers($targetEntity)))];
     }
     $this->form = $this->formFactory->createNamed($this->formName, $this->formType, $entity, $options);
     $this->form->setData($entity);
     if (in_array($this->request->getMethod(), array('POST', 'PUT'))) {
         $this->form->submit($this->request);
         if ($this->form->isValid()) {
             if ($targetEntityClass) {
                 $targetEntity = $this->entityRoutingHelper->getEntity($targetEntityClass, $targetEntityId);
                 $this->callActivityManager->addAssociation($entity, $targetEntity);
                 $phones = $this->phoneProvider->getPhoneNumbers($targetEntity);
                 foreach ($phones as $phone) {
                     if ($entity->getPhoneNumber() === $phone[0]) {
                         $this->callActivityManager->addAssociation($entity, $phone[1]);
                     }
                 }
             }
             $this->onSuccess($entity);
             return true;
         }
     }
     return false;
 }
開發者ID:rodolfobandeira,項目名稱:crm,代碼行數:42,代碼來源:CallHandler.php

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

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

示例10: getLoginForm

 /**
  * @param null $data
  * @param array $options
  * @return \Symfony\Component\Form\Form
  */
 public function getLoginForm($data = null, array $options = [])
 {
     $options['last_username'] = $this->authenticationUtils->getLastUsername();
     if (!array_key_exists('action', $options)) {
         $options['action'] = $this->router->generate('security_login_check');
     }
     return $this->formFactory->create(LoginType::class, $data, $options);
 }
開發者ID:ampisoft,項目名稱:user-bundle,代碼行數:13,代碼來源:FormManager.php

示例11: createAction

 /**
  * @Route("/users/new", name="user_new")
  * @Template("BigfishUserBundle:Default:form.html.twig")
  */
 public function createAction(Request $request)
 {
     $user = $this->_security->getToken()->getUser();
     $entity = $this->_userManager->createUser();
     $form = $this->_formFactory->create(new UserType(), $entity);
     //        $this->_formFactory->create(, $data, $options);
     return array('form' => $form->createView());
 }
開發者ID:BigfishCMF,項目名稱:UserBundle,代碼行數:12,代碼來源:DefaultController.php

示例12: shouldNotBindInvalidValue

    /**
     * @test
     */
    public function shouldNotBindInvalidValue()
    {
        $form = $this->formFactory->create('payum_payment_factories_choice');

        $form->submit('invalid');

        $this->assertNull($form->getData());
    }
開發者ID:xxspartan16,項目名稱:BMS-Market,代碼行數:11,代碼來源:PaymentFactoriesChoiceTypeTest.php

示例13: createForm

 /**
  * Create form for role manipulation
  *
  * @param Role $role
  * @return FormInterface
  */
 public function createForm(Role $role)
 {
     foreach ($this->privilegeConfig as $configName => $config) {
         $this->privilegeConfig[$configName]['permissions'] = $this->aclManager->getPrivilegeRepository()->getPermissionNames($config['types']);
     }
     $this->form = $this->formFactory->create(new ACLRoleType($this->privilegeConfig), $role);
     return $this->form;
 }
開發者ID:noglitchyo,項目名稱:pim-community-dev,代碼行數:14,代碼來源:AclRoleHandler.php

示例14: testLayout

 /**
  * @dataProvider layoutProvider
  */
 public function testLayout($formOptions, $formItems, $expectedBlocks)
 {
     $formBuilder = $this->factory->createNamedBuilder('test', 'form', null, $formOptions);
     $this->buildForm($formBuilder, $formItems);
     $formView = $formBuilder->getForm()->createView();
     $result = $this->builder->build($formView);
     $expected = $this->getBlocks($expectedBlocks);
     $this->assertEquals($expected, $result->toArray());
 }
開發者ID:Maksold,項目名稱:platform,代碼行數:12,代碼來源:DataBlockBuilderTest.php

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


注:本文中的Symfony\Component\Form\FormFactory類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。