public createNamed ( $name, $type = 'form', $data = null, array $options = [], Symfony\Component\Form\FormBuilderInterface $parent = null ) | ||
$options | array | |
$parent | Symfony\Component\Form\FormBuilderInterface |
/** * 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; }
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))); } }
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))); } }
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))))); } }
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)); }
/** * @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()); } }
/** * 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; }
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(); }); }
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)); } }
/** * @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)); }
/** * @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); }
/** * @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; }
protected function _initialiseForm() { $form = $this->_factory->createNamed($this->_name, 'form', $this->_defaultValues, $this->_options); $this->_initialised = true; return $form; }