/** * {@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; } } }
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); }
/** * @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()]; }
/** * 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; }
/** * @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); }
/** * 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; }
/** * 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; }
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); }
/** * @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); }
/** * @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()); }
/** * @test */ public function shouldNotBindInvalidValue() { $form = $this->formFactory->create('payum_payment_factories_choice'); $form->submit('invalid'); $this->assertNull($form->getData()); }
/** * 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; }
/** * @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()); }
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; }
/** * @Route("/") * @Method("post") */ public function indexPostAction(Request $request) { $form = $this->form_factory->create('blog_article'); $form->handleRequest($request); if ($form->isValid()) { $this->service->add($form->getData()); return $this->redirect($this->generateUrl('app_admin_blogpost_complete')); } return $this->render('Admin/Blog/index.html.twig', ['form' => $form->createView()]); }
/** * @ApiDoc( * description="Create a new Object", * formType="DinnerTime\UserInterface\RestBundle\Form\MenuCardType" * ) * @param Request $request * @param Restaurant $restaurant * * @return View */ public function postMenucardsAction(Request $request, Restaurant $restaurant) { $form = $this->formFactory->create(new MenuCardType(), new AddNewMenuCardToRestaurantCommand($restaurant)); $form->submit($request->request->all()); if ($form->isValid()) { $this->useCase->handle($form->getData()); return View::create($form->getData(), Codes::HTTP_CREATED); } return View::create($form); }
/** * {@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); }
/** * Builds form given success and fail urls * * @param $responseRoute * @return FormBuilder */ public function buildForm($responseRoute) { $formBuilder = $this->formFactory->createNamedBuilder(null); $orderId = $this->paymentBridge->getOrderId() . '#' . date('Ymdhis'); $fields = array('usuario' => $this->user, 'gran_total' => $this->paymentBridge->getAmount(), 'referencia' => $this->paymentBridge->getOrderDescription(), 'url_respuesta' => $responseRoute); //echo $this->cps;die(); $formKey = $this->encryptor->encrypt(implode('', $fields)); $formBuilder->setAction($this->gateway)->setMethod('POST')->add('usuario', 'hidden', array('data' => $this->user))->add('gran_total', 'hidden', array('data' => $this->paymentBridge->getAmount()))->add('referencia_ext', 'hidden', array('data' => $this->paymentBridge->getOrderDescription()))->add('url_respuesta', 'hidden', array('data' => $responseRoute))->add('key', 'hidden', array('data' => $formKey))->add('order_id', 'hidden', array('data' => $orderId))->add('Submit', 'hidden', array('data' => 'Pagar')); return $formBuilder; }
/** * @Route("/", name="category_registration_save") * @Method("post") */ public function saveAction(Request $request) { $form = $this->form_factory->create('category'); $form->handleRequest($request); if ($form->isValid()) { $this->service->add($form->getData()); return $this->redirect($this->generateUrl('app_admin_category_complete')); } return $this->render('Admin/Category/Registration/index.html.twig', ['form' => $form->createView()]); }
public function testInvalidTest() { $twig = new \Twig_Environment(new \Twig_Loader_Array(array('template' => '{{ form is invalid ? 1 : 0 }}'))); $twig->addExtension(new FormExtension()); $formWithError = $this->formFactory->create('text'); $formWithError->addError(new FormError('test error')); $this->assertEquals('1', $twig->render('template', array('form' => $formWithError->createView()))); $formWithoutError = $this->formFactory->create('text'); $this->assertEquals('0', $twig->render('template', array('form' => $formWithoutError->createView()))); }
/** * @Route("/{id}", name="category_edit_post") * @ParamConverter("category", class="AppBundle:Category") * @Method("post") */ public function editPostAction(Request $request, Category $category) { $form = $this->form_factory->create('category', $category); $form->handleRequest($request); if ($form->isValid()) { $this->service->update(); return $this->redirect($this->generateUrl('admin_category')); } return $this->render('Admin/Category/Registration/index.html.twig', ['form' => $form->createView()]); }
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))); } }
/** * Builds form given return, success and fail urls. * * @return FormView */ public function buildForm() { $formBuilder = $this->formFactory->createNamedBuilder(null); $orderId = $this->paymentBridge->getOrderId(); $orderCurrency = $this->paymentBridge->getCurrency(); $this->checkCurrency($orderCurrency); /** * Creates the success return route, when coming back * from PayPal web checkout. */ $successReturnUrl = $this->urlFactory->getSuccessReturnUrlForOrderId($orderId); /** * Creates the cancel payment route, when cancelling * the payment process from PayPal web checkout. */ $cancelReturnUrl = $this->urlFactory->getCancelReturnUrlForOrderId($orderId); /** * Creates the IPN payment notification route, * which is triggered after PayPal processes the * payment and returns the validity of the transaction. * * For forther information * * https://developer.paypal.com/docs/classic/ipn/integration-guide/IPNandPDTVariables/ * https://developer.paypal.com/webapps/developer/docs/classic/ipn/integration-guide/IPNIntro/ */ $processUrl = $this->urlFactory->getProcessUrlForOrderId($orderId); $formBuilder->setAction($this->urlFactory->getApiEndpoint())->setMethod('POST')->add('business', 'hidden', ['data' => $this->business])->add('return', 'hidden', ['data' => $successReturnUrl])->add('cancel_return', 'hidden', ['data' => $cancelReturnUrl])->add('notify_url', 'hidden', ['data' => $processUrl])->add('currency_code', 'hidden', ['data' => $orderCurrency])->add('env', 'hidden', ['data' => '']); /** * Create a PayPal cart line for each order line. * * Project specific PaymentBridgeInterface::getExtraData * should return an array of this form * * ['items' => [ * 0 => [ 'item_name' => 'Item 1', 'amount' => 1234, 'quantity' => 2 ], * 1 => [ 'item_name' => 'Item 2', 'amount' => 2345, 'quantity' => 1 ], * ]] * * The 'items' key consists of an array with the basic information * of each line of the order. Amount is the price of the product, * not the total of the order line */ $cartData = $this->paymentBridge->getExtraData(); $itemsData = $cartData['items']; $iteration = 1; foreach ($itemsData as $orderLine) { $formBuilder->add('item_name_' . $iteration, 'hidden', ['data' => $orderLine['item_name']])->add('amount_' . $iteration, 'hidden', ['data' => $orderLine['amount'] / 100])->add('quantity_' . $iteration, 'hidden', ['data' => $orderLine['quantity']]); ++$iteration; } if (isset($cartData['discount_amount_cart'])) { $formBuilder->add('discount_amount_cart', 'hidden', ['data' => $cartData['discount_amount_cart'] / 100]); } return $formBuilder->getForm()->createView(); }
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))); } }
/** * @Route("comment/{id}") * @ParamConverter("blog", class="AppBundle:BlogArticle") * @Method("post") */ public function createAction(Request $request, BlogArticle $blog) { $comment = new Comment($blog); $form = $this->form_factory->create('comment', $comment); $form->handleRequest($request); if ($form->isValid()) { $this->service->add($comment); return $this->redirect($this->generateUrl('app_blog_show', ['id' => $blog->getId()])); } return $this->render('Comment/form.html.twig', ['form' => $form->createView(), 'comment' => $comment]); }
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()]); }
/** * @Route() * @Method("POST") * * @param Request $request * @return RedirectResponse */ public function saveAction(Request $request) { $form = $this->formFactory->create('todo'); $form->handleRequest($request); if ($form->isValid()) { $this->addTodo->run($form->getData()); $this->notification->info('タスクを登録しました'); } else { $this->notification->danger('タスクの登録に失敗しました'); } return new RedirectResponse($this->router->generate('app_todo_default_index')); }
/** * @Route("/newsletter/new", name="newsletter_new") * * @return Response * * @throws \Exception * @throws \Twig_Error */ public function newAction(Request $request) { $resolvedForm = $this->formFactory->create(new NewsletterCampaignFormType()); if ($request->isMethod("POST")) { $resolvedForm->handleRequest($request); if ($resolvedForm->isValid()) { $newsletterCampaign = $resolvedForm->getData(); $this->newsletterCampaignManager->save($newsletterCampaign); $this->session->getFlashBag()->add('message', 'Saved!'); } } return new Response($this->twig->render('AppBundle:Newsletter:new.html.twig', array('form' => $resolvedForm->createView(), ''))); }
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 testRender() { $options = array('block_config' => array('first' => array('priority' => 1, 'title' => 'First Block', 'subblocks' => array('first' => array(), 'second' => array('title' => 'Second SubBlock')), 'description' => 'some desc'), 'second' => array('priority' => 2))); $builder = $this->factory->createNamedBuilder('test', 'form', null, $options); $builder->add('text_1', null, array('block' => 'first', 'subblock' => 'second')); $builder->add('text_2', null, array('block' => 'first')); $builder->add('text_3', null, array('block' => 'second')); $builder->add('text_4', null, array('block' => 'third')); $builder->add('text_5', null, array('block' => 'third', 'subblock' => 'first')); $builder->add('text_6', null); $formView = $builder->getForm()->createView(); $result = $this->renderer->render($this->twig, array('form' => $formView), $formView); $this->assertEquals($this->testFormConfig, $result); }