/** * @param Form $form * * @return mixed * @throws \Exception * @throws \PaymentSuite\PaymentCoreBundle\Exception\PaymentException */ private function processPaymentData(Form $form) { if ($form->isValid()) { $data = $form->getData(); $paymentMethod = new AuthorizenetMethod(); $paymentMethod->setCreditCartNumber($data['credit_cart'])->setCreditCartExpirationMonth($data['credit_cart_expiration_month'])->setCreditCartExpirationYear($data['credit_cart_expiration_year']); try { $this->get('authorizenet.manager')->processPayment($paymentMethod); $redirectUrl = $this->container->getParameter('authorizenet.success.route'); $redirectAppend = $this->container->getParameter('authorizenet.success.order.append'); $redirectAppendField = $this->container->getParameter('authorizenet.success.order.field'); } catch (PaymentException $e) { /** * Must redirect to fail route */ $redirectUrl = $this->container->getParameter('authorizenet.fail.route'); $redirectAppend = $this->container->getParameter('authorizenet.fail.order.append'); $redirectAppendField = $this->container->getParameter('authorizenet.fail.order.field'); throw $e; } } else { /** * If form is not valid, fail return page */ $redirectUrl = $this->container->getParameter('authorizenet.fail.route'); $redirectAppend = $this->container->getParameter('authorizenet.fail.order.append'); $redirectAppendField = $this->container->getParameter('authorizenet.fail.order.field'); } $redirectData = $redirectAppend ? array($redirectAppendField => $this->get('payment.bridge')->getOrderId()) : array(); $returnData['redirectUrl'] = $redirectUrl; $returnData['redirectData'] = $redirectData; return $returnData; }
public function persistTranslations(Form $form, $class, $field, $id, $locales, $userLocale) { $translations = $form->getData(); $em = $this->em; $repository = $em->getRepository($class); $entity = $repository->find($id); // loop on locales // parse form data // get data stored in db // set form data on object if needed foreach ($locales as $locale) { if (array_key_exists($locale, $translations) && $translations[$locale] !== NULL) { $entity->setTranslatableLocale($locale); $em->refresh($entity); $postedValue = $translations[$locale]; $storedValue = $this->getField($entity, $field); if ($storedValue !== $postedValue) { $this->setField($entity, $field, $postedValue); $em->flush(); } } } // switch entity locale back to user's locale $this->setEntityToUserLocale($entity, $userLocale); }
protected function onCreateSuccess(Form $form) { $this->container->get('lichess_comment.authorname_persistence')->persistCommentInSession($form->getData()); $response = parent::onCreateSuccess($form); $this->container->get('lichess_comment.authorname_persistence')->persistCommentInCookie($form->getData(), $response); return $response; }
/** * {@inheritdoc} */ public function handle(Form $form, $webSpaceKey, array $options = []) { $data = $form->getData(); $user = $this->userRepository->findOneBy(['confirmationKey' => $data['token']]); $user->setConfirmationKey(null); if ($options[Configuration::ACTIVATE_USER]) { if ($user instanceof BaseUser) { $user->setEnabled(true); } } $this->entityManager->persist($user); $this->entityManager->flush(); return $user; }
public function testRequestWithValidJsonShouldPopulateForm() { $request = $this->getRequest('{ "name": "test1" }'); $this->form->handleRequest($request); $this->assertEquals(['name' => 'test1', 'lastname' => null], $this->form->getData()); $this->assertEquals(['name' => 'test1', 'lastname' => null], $this->form->getNormData()); $this->assertEquals(['name' => 'test1', 'lastname' => null], $this->form->getViewData()); }
/** * @return boolean */ public function process() { $this->form->submit($this->request); if ($this->form->isValid()) { $query = $this->form->getData()->getQuery(); return true; } return false; }
/** * @param \Symfony\Component\Form\Form $form * @param \FSi\Bundle\AdminBundle\Admin\CRUD\FormElement $element * @param \FSi\Component\DataIndexer\DataIndexerInterface $dataIndexer * @param \Symfony\Component\HttpFoundation\Request $request */ function it_have_array_data($form, $element, $dataIndexer, $request) { $form->createView()->willReturn('form_view'); $form->getData()->willReturn(null); $this->handleRequest($request)->shouldReturn(null); $this->getData()->shouldBeArray(); $this->getData()->shouldHaveKeyInArray('form'); $this->getData()->shouldHaveKeyInArray('element'); $form->getData()->willReturn(array('object')); $element->getDataIndexer()->willReturn($dataIndexer); $dataIndexer->getIndex(array('object'))->willReturn('id'); $this->getData()->shouldHaveKeyInArray('id'); }
/** * @return boolean */ public function process() { $this->form->submit($this->request); if ($this->form->isValid()) { $entityModel = $this->form->getData(); $this->entity->setContent($this->sanitizer->doClean($entityModel->getContent())); $this->entity->setUserName($this->sanitizer->doClean($entityModel->getUserName())); $this->entity->setUserEmail($this->sanitizer->doClean($entityModel->getUserEmail())); $this->entity->setUserWeb($this->sanitizer->doClean($entityModel->getUserWeb())); $this->em->persist($this->entity); $this->em->flush(); return true; } return false; }
/** * @Route("/datapresentation/filter_set", name="datapresentation_filter_set") */ public function filterSetAction(Request $request) { $this->init($request); $this->initForm(); if ($this->form->isSubmitted() && $this->form->isValid()) { $filters = $this->form->getData(); unset($filters['today']); $filtersString = serialize($filters); $cookie = new Cookie('filters', $filtersString, time() + 3600 * 24 * 7, '/'); $response = new Response(); $response->headers->setCookie($cookie); $response->send(); $this->request->cookies->set('filters', $filtersString); } return $this->redirectToRoute('datapresentation'); }
/** * checkFilters * * Build filters form * If the method POST filters are constructed and written to the session * else if in session is a form of filter-it is Otherwise, * if there is a default filters-they are * * @param array $default (stand default filter (option)) * @return */ protected function checkFilters($default = array()) { if ($this->filter_fields) { $this->filter_form = $this->createForm(new BuilderFormFilterType($this->filter_fields)); if (count($default)) { $this->filter_form->setData($default); } $method = $this->query instanceof NativeQuery ? 'buildNativeQuery' : 'buildQuery'; if ($this->get('request')->getMethod() == 'POST') { $this->get('session')->remove('_filter_' . $this->get('request')->get('_route')); $this->get('session')->remove('_pager_' . $this->get('request')->get('_route')); $this->filter_form->bind($this->get('request')); $this->get('zk2_admin_panel.query_builder')->{$method}($this->filter_form, $this->query); $filterService = $this->get('zk2_admin_panel.form_filter_session'); $filterService->serialize($this->filter_form->getData(), '_filter_' . $this->get('request')->get('_route')); } elseif ($this->get('session')->has('_filter_' . $this->get('request')->get('_route'))) { $filterService = $this->get('zk2_admin_panel.form_filter_session'); $data = $filterService->unserialize('_filter_' . $this->get('request')->get('_route'), $this->em_name); $this->filter_form->setData($data); $this->get('zk2_admin_panel.query_builder')->{$method}($this->filter_form, $this->query); } elseif (count($default)) { $this->get('zk2_admin_panel.query_builder')->{$method}($this->filter_form, $this->query); } } }
/** * {@inheritdoc} */ public function handle(Form $form, $webSpaceKey, array $options = []) { $user = $form->getData(); $user = $this->setUserData($form, $user); $this->entityManager->persist($user); $this->entityManager->flush(); return $user; }
/** * @param Form $form * @param Request $request * * @return bool */ public function processValidForm(Form $form, Request $request) { $data = $form->getData(); if ($data->hasExampleData() === true) { $data->addModule('Blog'); } $request->getSession()->set('installation_data', $data); return true; }
public function process() { if ($this->form->isValid()) { if ('POST' == $this->request->getMethod()) { /** @var Apply $apply */ $apply = $this->form->getData(); $apply_email = $this->em->getRepository('ESNHRBundle:Apply')->findOneByEmail($apply->getEmail()); $apply_name = $this->em->getRepository('ESNHRBundle:Apply')->findBy(array("firstname" => $apply->getFirstname(), "lastname" => $apply->getLastname())); if (!$apply_email && !$apply_name) { $this->onSuccess($apply); return true; } else { $this->container->get('session')->getFlashBag()->add('error', 'Vous êtes déjà enregistré dans notre base de données, il est inutile de postuler plusieurs fois.'); } } } return false; }
function let(ProductRepositoryInterface $productRepository, UniqueValuesSet $uniqueValuesSet, ExecutionContextInterface $context, Form $form, ProductInterface $product, ProductValueInterface $value) { $this->beConstructedWith($productRepository, $uniqueValuesSet); $product->getValue('unique_attribute')->willReturn($value); $form->getData()->willReturn($product); $context->getPropertyPath()->willReturn(self::PROPERTY_PATH); $context->getRoot()->willReturn($form); $this->initialize($context); }
/** * @param Form $form */ protected function persistData(Form $form) { /** @var $userManager \FOS\UserBundle\Model\UserManagerInterface */ $userManager = $this->get('fos_user.user_manager'); $userManager->updateUser($form->getData()); $objectManager = $this->getDoctrine()->getManager(); $objectManager->persist($form->getData()); $objectManager->flush(); }
public function testDataIsInitializedEmpty() { $norm = new FixedDataTransformer(array('' => 'foo')); $client = new FixedDataTransformer(array('foo' => 'bar')); $form = new Form('name', $this->dispatcher, array(), array($client), array($norm)); $this->assertNull($form->getData()); $this->assertSame('foo', $form->getNormData()); $this->assertSame('bar', $form->getClientData()); }
function let(ProductManager $productManager, ExecutionContextInterface $context, Form $form, ProductInterface $product, ProductValueInterface $value) { $this->beConstructedWith($productManager); $product->getValue('sku')->willReturn($value); $form->getData()->willReturn($product); $context->getPropertyPath()->willReturn(self::PROPERTY_PATH); $context->getRoot()->willReturn($form); $this->initialize($context); }
/** * @param Request $request * @param Form $form * * @return array|boolean */ public function handleConfigForm(Request $request, Form $form) { if ($request->isMethod('post')) { $form->handleRequest($request); if ($form->isValid()) { return $form->getData(); } } return false; }
/** * @param Form $form * @param Request $request * * @return bool */ public function processValidForm(Form $form, Request $request) { $data = $form->getData(); // different fields for single and multiple language $data->setLanguages($data->getLanguageType() === 'multiple' ? $data->getLanguages() : array($data->getDefaultLanguage())); // take same_interface_language field into account $data->setInterfaceLanguages($data->getSameInterfaceLanguage() === true ? $data->getLanguages() : $data->getInterfaceLanguages()); $request->getSession()->set('installation_data', $data); return true; }
public function process(Form $form) { $data = $form->getData(); $message = \Swift_Message::newInstance()->setSubject($this->subjectResolver->getSubject($form))->setContentType("text/plain")->setBody($data["body"])->addFrom($data["email"], $data["name"]); //add recipients foreach ($this->recipients[$data["recipients"]]["recipients"] as $address) { $message->addTo($address); } $this->mailer->send($message); }
/** * Process current form * @return boolean */ public function process() { $success = false; if ($this->request->getMethod() == 'POST' || $this->request->getMethod() == 'PUT') { // Correct HTTP method => try to process form $this->form->submit($this->request); if ($this->form->isValid()) { // Form is valid => create or update the path $this->data = $this->form->getData(); if ($this->request->getMethod() == 'POST') { // Create path $success = $this->create(); } else { // Edit existing path $success = $this->edit(); } } } return $success; }
public function testDataIsInitializedEmpty() { $model = new FixedDataTransformer(array('' => 'foo')); $view = new FixedDataTransformer(array('foo' => 'bar')); $config = new FormConfig('name', null, $this->dispatcher); $config->addViewTransformer($view); $config->addModelTransformer($model); $form = new Form($config); $this->assertNull($form->getData()); $this->assertSame('foo', $form->getNormData()); $this->assertSame('bar', $form->getViewData()); }
/** * @param Form $form * @param Request $request * @return bool|\Symfony\Component\HttpFoundation\RedirectResponse */ private function handleFormRequest(Form $form, Request $request) { $form->handleRequest($request); if (!$form->isValid()) { return false; } $userEntity = $this->initUser($form->getData()); $em = $this->getDoctrine()->getManager(); $em->persist($userEntity); $em->flush(); return true; }
/** * @param Form $form * @param Request $request * @param array $options * * @return bool */ public function handle(Form $form, Request $request, array $options = null) { if (!$request->isMethod('POST')) { return false; } $form->bind($request->request->get($form->getName())); if (!$form->isBound() || !$form->isValid()) { return false; } $this->usermanager->createUser($form->getData()->getUser()); return true; }
public function testDataIsInitializedToConfiguredValue() { $model = new FixedDataTransformer(array('default' => 'foo')); $view = new FixedDataTransformer(array('foo' => 'bar')); $config = new FormConfigBuilder('name', null, $this->dispatcher); $config->addViewTransformer($view); $config->addModelTransformer($model); $config->setData('default'); $form = new Form($config); $this->assertSame('default', $form->getData()); $this->assertSame('foo', $form->getNormData()); $this->assertSame('bar', $form->getViewData()); }
protected function processForm($type, Form $form) { $repo = $this->get('social.publishing.repository'); $form->handleRequest($this->getRequest()); // remove the current edited entity from the listing if (!is_null($form->getData())) { $param['skipped_pub'] = $form->getData()->getId(); } if ($form->isValid()) { $newPost = $form->getData(); try { $repo->persist($newPost); $this->pushFlash('notice', 'Message saved'); return $this->redirectRouteOk('wall_index', ['wallNick' => $this->getUser()->getUsername(), 'wallFilter' => 'self'], 'anchor-' . $newPost->getId()); } catch (\MongoException $e) { $this->pushFlash('warning', 'Cannot save message'); } } $param['form'] = $form->createView(); $template = "TrismegisteSocialBundle:Content:form/{$type}.html.twig"; return $this->renderWall($this->getUser()->getUsername(), 'self', $template, $param); }
public function getRecipient(Form $form) { switch ($this->subjectFieldType) { case "text": $recipients = explode(",", $this->recipients); break; case "dropdown": $data = $form->getData(); $recipients = explode(",", $data["subject"]); break; } return $recipients; }
public function validate(Form $form) { if (!$form->has('uploadedProductImages')) { return TRUE; } if ($form->get('uploadedProductImages')->isRequired() && !array_filter($form->getData()->getUploadedProductImages())) { $form->get('uploadedProductImages')->addError(new FormError($this->_translator->trans('product.uploaded_product_images.not_blank', [], 'validators'))); return FALSE; } foreach ($form->getData()->getUploadedProductImages() as $uploadedProductImage) { $productImage = (new ProductImage())->setImageProductFile($uploadedProductImage); $errors = $this->_validator->validate($productImage); if (count($errors) === 0) { return TRUE; } foreach ($errors as $error) { $form->get('uploadedProductImages')->addError(new FormError($error->getMessage())); } return FALSE; } return TRUE; }
/** * @param Form $form * @param Request $request * * @return bool */ public function process(Form $form, Request $request) { if (!$request->isMethod('POST')) { return false; } $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { $data = $form->getData(); $this->em->persist($data); $this->em->flush(); return true; } return false; }
private function isValid(Request $request, Form $form) { $session = $request->getSession(); if ('POST' === $request->getMethod()) { $form->handleRequest($request); if ($form->isValid()) { $sessionData = $session->get(self::SESSION_KEY) ?: array(); $formData = array_replace_recursive($sessionData, $form->getData()); $session->set(self::SESSION_KEY, $formData); return true; } } return false; }