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


PHP FormFactory::createNamed方法代码示例

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


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

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

示例2: onPreSetData

 public function onPreSetData(FormEvent $event)
 {
     $form = $event->getForm();
     if ($this->account->isRothIraType() || $this->account->isTraditionalIraType()) {
         $form->add($this->factory->createNamed('distribution_method', 'choice', null, array('choices' => Distribution::getDistributionMethodChoices(), 'expanded' => true, 'multiple' => false, 'required' => false)))->add($this->factory->createNamed('federal_withholding', 'choice', null, array('choices' => Distribution::getFederalWithholdingChoices(), 'expanded' => true, 'multiple' => false, 'required' => false)))->add($this->factory->createNamed('state_withholding', 'choice', null, array('choices' => Distribution::getStateWithholdingChoices(), 'expanded' => true, 'multiple' => false, 'required' => false)))->add($this->factory->createNamed('federal_withhold_percent', 'percent', null, array('required' => false)))->add($this->factory->createNamed('federal_withhold_money', 'number', null, array('precision' => 2, 'grouping' => true, 'required' => false)))->add($this->factory->createNamed('state_withhold_percent', 'percent', null, array('required' => false)))->add($this->factory->createNamed('state_withhold_money', 'number', null, array('precision' => 2, 'grouping' => true, 'required' => false)))->add($this->factory->createNamed('residenceState', 'entity', null, array('class' => 'WealthbotAdminBundle:State', 'label' => 'State', 'empty_value' => 'Select a State', 'required' => false)));
     }
 }
开发者ID:junjinZ,项目名称:wealthbot,代码行数:7,代码来源:ScheduledDistributionFormType.php

示例3: addFees

 public function addFees(FormEvent $event)
 {
     /* @var $billingSpec BillingSpec */
     $billingSpec = $event->getData();
     //Attach a tier form
     if ($billingSpec->getType() == BillingSpec::TYPE_TIER) {
         $event->getForm()->add($this->factory->createNamed('fees', 'collection', $billingSpec->getFees(), array('type' => new TierFeeFormType(), 'allow_add' => true, 'by_reference' => false)));
     } elseif ($billingSpec->getType() == BillingSpec::TYPE_FLAT) {
         $event->getForm()->add($this->factory->createNamed('fees', 'collection', $billingSpec->getFees(), array('type' => new FlatFeeFormType(), 'allow_add' => true, 'by_reference' => false)));
     }
 }
开发者ID:junjinZ,项目名称:wealthbot,代码行数:11,代码来源:BillingSpecFormType.php

示例4: preSetData

 public function preSetData(FormEvent $event)
 {
     /** @var $data CeModel */
     $data = $event->getData();
     $form = $event->getForm();
     if (null === $data) {
         return;
     }
     // check if the product object is not "new"
     if ($data->getId()) {
         //$modelsCount = $this->em->getRepository('WealthbotAdminBundle:CeModel')->getModelsCountByParentIdAndOwnerId($data->getParent()->getId(), $data->getOwnerId());
         $form->add($this->factory->createNamed('risk_rating', 'choice', $data->getRiskRating(), array('empty_value' => 'Select Risk Rating', 'choices' => array_combine(range(1, 100), range(1, 100)))));
     }
 }
开发者ID:junjinZ,项目名称:wealthbot,代码行数:14,代码来源:CeModelFormTypeEventsListener.php

示例5: testCreateNamed

    public function testCreateNamed()
    {
        $options = array('a' => '1', 'b' => '2');
        $resolvedOptions = array('a' => '2', 'b' => '3');
        $resolvedType = $this->getMockResolvedType();

        $this->registry->expects($this->once())
            ->method('getType')
            ->with('type')
            ->will($this->returnValue($resolvedType));

        $resolvedType->expects($this->once())
            ->method('createBuilder')
            ->with($this->factory, 'name', $options)
            ->will($this->returnValue($this->builder));

        $this->builder->expects($this->any())
            ->method('getOptions')
            ->will($this->returnValue($resolvedOptions));

        $resolvedType->expects($this->once())
            ->method('buildForm')
            ->with($this->builder, $resolvedOptions);

        $this->builder->expects($this->once())
            ->method('getForm')
            ->will($this->returnValue('FORM'));

        $this->assertSame('FORM', $this->factory->createNamed('name', 'type', null, $options));
    }
开发者ID:symfony,项目名称:symfony,代码行数:30,代码来源:FormFactoryTest.php

示例6: testAddFormErrorIfPostMaxSizeExceeded

    /**
     * @dataProvider getPostMaxSizeFixtures
     */
    public function testAddFormErrorIfPostMaxSizeExceeded($contentLength, $iniMax, $shouldFail, array $errorParams = array())
    {
        $this->serverParams->expects($this->once())
            ->method('getContentLength')
            ->will($this->returnValue($contentLength));
        $this->serverParams->expects($this->any())
            ->method('getNormalizedIniPostMaxSize')
            ->will($this->returnValue($iniMax));

        $options = array('post_max_size_message' => 'Max {{ max }}!');
        $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType', null, $options);
        $this->setRequestData('POST', array(), array());

        $this->requestHandler->handleRequest($form, $this->request);

        if ($shouldFail) {
            $error = new FormError($options['post_max_size_message'], null, $errorParams);
            $error->setOrigin($form);

            $this->assertEquals(array($error), iterator_to_array($form->getErrors()));
            $this->assertTrue($form->isSubmitted());
        } else {
            $this->assertCount(0, $form->getErrors());
            $this->assertFalse($form->isSubmitted());
        }
    }
开发者ID:symfony,项目名称:symfony,代码行数:29,代码来源:AbstractRequestHandlerTest.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()) {
             $phone = $this->request->query->get('phone');
             if (!$phone) {
                 $phone = $this->phoneProvider->getPhoneNumber($targetEntity);
             }
             $entity->setPhoneNumber($phone);
         }
         $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()) {
             // TODO: should be refactored after finishing BAP-8722
             // Contexts handling should be moved to common for activities form handler
             if ($this->form->has('contexts')) {
                 $contexts = $this->form->get('contexts')->getData();
                 $this->activityManager->setActivityTargets($entity, $contexts);
             } elseif ($targetEntityClass) {
                 // if we don't have "contexts" form field
                 // we should save association between activity and target manually
                 $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:antrampa,项目名称:crm,代码行数:53,代码来源:CallHandler.php

示例8: configureCollectionSearch

 protected function configureCollectionSearch()
 {
     // Form instance
     // Form object to bind
     return array('create_form' => function () {
         return $this->formFactory->createNamed('search', new CollectionType());
     }, 'create_form_object' => function () {
         return new Collection();
     });
 }
开发者ID:rpg600,项目名称:FSCRestBundle,代码行数:10,代码来源:AbstractResource.php

示例9: preSubmitData

 public function preSubmitData(FormEvent $event)
 {
     $data = $event->getData();
     if (!$data) {
         $data = $event->getForm()->getParent()->getData();
     }
     $form = $event->getForm();
     $targetEntity = null;
     if (isset($data['target_entity'])) {
         $targetEntity = $data['target_entity'];
     }
     $relationType = $this->config->getId()->getFieldType();
     if ($relationType == 'manyToOne') {
         //target_field
         $targetField = null;
         if (isset($data['target_field'])) {
             $targetField = $data['target_field'];
         }
         $form->add($this->formFactory->createNamed('target_field', new TargetFieldType($this->configProvider, $targetEntity), $targetField));
     } else {
         //target_grid
         $targetGrid = null;
         if (isset($data['target_grid'])) {
             $targetGrid = $data['target_grid'];
         }
         $form->add($this->formFactory->createNamed('target_grid', new TargetFieldType($this->configProvider, $targetEntity), $targetGrid, ['multiple' => true, 'label' => 'Related entity data fields']));
         //target_title
         $targetTitle = null;
         if (isset($data['target_title'])) {
             $targetTitle = $data['target_title'];
         }
         $form->add($this->formFactory->createNamed('target_title', new TargetFieldType($this->configProvider, $targetEntity), $targetTitle, ['multiple' => true, 'label' => 'Related entity info title']));
         //target_detailed
         $targetDetailed = null;
         if (isset($data['target_detailed'])) {
             $targetDetailed = $data['target_detailed'];
         }
         $form->add($this->formFactory->createNamed('target_detailed', new TargetFieldType($this->configProvider, $targetEntity), $targetDetailed, ['multiple' => true, 'label' => 'Related entity detailed']));
     }
     if ($event->getName() == FormEvents::PRE_SUBMIT) {
         $event->getForm()->getParent()->setData(array_merge($event->getForm()->getParent()->getData(), $data));
     }
 }
开发者ID:ashutosh-srijan,项目名称:findit_akeneo,代码行数:43,代码来源:RelationType.php

示例10: addTargetField

 /**
  * @param FormInterface $form
  * @param string        $name
  * @param string        $targetEntityClass
  * @param array|null    $data
  * @param string|null   $label
  * @param bool          $multiple
  */
 protected function addTargetField(FormInterface $form, $name, $targetEntityClass, $data = null, $label = null, $multiple = false)
 {
     $options = [];
     $options['constraints'] = [new Assert\NotBlank()];
     if ($label) {
         $options['label'] = $label;
     }
     if ($multiple) {
         $options['multiple'] = true;
     }
     $form->add($this->formFactory->createNamed($name, new TargetFieldType($this->configProvider, $targetEntityClass), $data, $options));
 }
开发者ID:xamin123,项目名称:platform,代码行数:20,代码来源:RelationType.php

示例11: executeNamed

 /**
  * @param string $name
  * @param mixed $target
  * @param Request $request
  * @param string|\Symfony\Component\Form\FormTypeInterface $formType
  * @return \WS\Libraries\Listor\IterableInterface
  */
 public function executeNamed($name, $target, Request $request, $formType = 'ws_listor')
 {
     $form = $this->formFactory->createNamed($name, $formType);
     $form->handleRequest($request);
     $data = $form->isValid() ? $form->getData() : array();
     $params = array();
     if (array_key_exists('current_page', $data)) {
         $params['currentPage'] = $data['current_page'];
     } else {
         if ($request->attributes->has('currentPage')) {
             $params['currentPage'] = $request->attributes->get('currentPage', 0);
         } else {
             $params['currentPage'] = $request->query->get('currentPage', 0);
         }
     }
     if (array_key_exists('items_per_page', $data)) {
         $params['itemsPerPage'] = $data['items_per_page'];
     } else {
         $params['itemsPerPage'] = $this->itemsPerPage;
     }
     $filters = array_key_exists('filters', $data) ? $data['filters'] : array();
     return IterableRequest::fromBaseIterable($this->listor->execute($target, $filters, $params), $request, $form);
 }
开发者ID:WedgeSama,项目名称:Listor,代码行数:30,代码来源:ListorRequest.php

示例12: prepareForm

 /**
  * @param $formParentName
  * @param $accountTypeModel
  * @return null|\Symfony\Component\Form\Form|FormInterface
  */
 protected function prepareForm($formParentName, $accountTypeModel)
 {
     $form = null;
     if ($formParentName === $this->userFormName) {
         $data = $user = new User();
         $data->setImapAccountType($accountTypeModel);
         $this->formUser->setData($data);
         $form = $this->formUser;
     } elseif ($formParentName === $this->emailMailboxFormName) {
         $data = $user = new Mailbox();
         $data->setImapAccountType($accountTypeModel);
         $form = $this->formFactory->createNamed($this->emailMailboxFormName, $this->emailMailboxFormType, null, ['csrf_protection' => false]);
         $form->setData($data);
     }
     return $form;
 }
开发者ID:woei66,项目名称:platform,代码行数:21,代码来源:ConnectionControllerManager.php

示例13: _initialiseForm

 protected function _initialiseForm()
 {
     $form = $this->_factory->createNamed($this->_name, 'form', $this->_defaultValues, $this->_options);
     $this->_initialised = true;
     return $form;
 }
开发者ID:mothership-ec,项目名称:cog,代码行数:6,代码来源:Handler.php


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