作者:pinode
项目:board
public static function handleFlashErrors(SymfonyForm $form, $identifier)
{
$errors = self::$app['flashbag']->get('form.' . $identifier . '.errors');
foreach ($errors as $error) {
$form->addError(new FormError($error));
}
}
作者:eddg311
项目:Req_1_CRU
protected function addField(Form $form, $municipio)
{
$formOptions = array('class' => 'SiSuCuentaBundle:Parroquia', 'empty_value' => '-- Seleccionar --', 'attr' => array('class' => 'usuario_parroquia'), 'required' => true, 'label' => 'Parroquia', 'query_builder' => function (EntityRepository $er) use($municipio) {
return $er->createQueryBuilder('parroquia')->where('parroquia.municipio = :municipio')->setParameter('municipio', $municipio);
});
$form->add('parroquia', 'entity', $formOptions);
}
作者:koesie1
项目:LuaSerialize
private function convertFormToArray(GenericSerializationVisitor $visitor, Form $data)
{
$isRoot = null === $visitor->getRoot();
$form = new \ArrayObject();
$errors = [];
foreach ($data->getErrors() as $error) {
$errors[] = $this->getErrorMessage($error);
}
if (!empty($errors)) {
$form['errors'] = $errors;
}
$children = [];
foreach ($data->all() as $child) {
if ($child instanceof Form) {
$children[$child->getName()] = $this->convertFormToArray($visitor, $child);
}
}
if (!empty($children)) {
$form['children'] = $children;
}
if ($isRoot) {
$visitor->setRoot($form);
}
return $form;
}
作者:haso
项目:paymentsuit
/**
* @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;
}
作者:JM-PF
项目:CEIP-S
protected function getErrorMessages(\Symfony\Component\Form\Form $form, $name)
{
$errors = array();
foreach ($form->getErrors() as $key => $error) {
$errors[] = $error->getMessage();
}
foreach ($form->all() as $child) {
$type = $child->getConfig()->getType()->getName();
if ($child->count() && $type !== 'choice') {
$childErrors = $this->getErrorMessages($child, $child->getName());
if (sizeof($childErrors)) {
$errors = array_merge($errors, $childErrors);
}
} else {
if (!$child->isValid()) {
if ($name == "responsable1" || $name == "responsable2") {
$errors[$child->getParent()->getParent()->getName() . '_' . $name . '_' . $child->getName()] = $this->getErrorMessages($child, $child->getName());
} else {
$errors[$name . '_' . $child->getName()] = $this->getErrorMessages($child, $child->getName());
}
}
}
}
return $errors;
}
作者:bol
项目:Member
/**
* {@inheritdoc}
*/
public function process(Request $request, $grantType = 'password')
{
$account = $this->records->getAccountByEmail($this->submittedForm->get('email')->getData());
if (!$account) {
return null;
}
$oauth = $this->records->getOauthByGuid($account->getGuid());
$requestPassword = $this->submittedForm->get('password')->getData();
if ($this->isValidPassword($oauth, $requestPassword) === false) {
return null;
}
$accessToken = $this->provider->getAccessToken('password', ['guid' => $account->getGuid()]);
$this->session->addAccessToken('local', $accessToken)->createAuthorisation($account->getGuid());
$request->query->set('code', Uuid::uuid4()->toString());
try {
parent::process($request, $grantType);
$this->finish($request);
$this->feedback->info('Login successful.');
} catch (DisabledAccountException $ex) {
$this->session->addRedirect($this->urlGenerator->generate('authenticationLogin'));
if ($this->session->getAuthorisation()) {
$this->dispatchEvent(MembersEvents::MEMBER_LOGIN_FAILED_ACCOUNT_DISABLED, $this->session->getAuthorisation());
}
}
return $this->session->popRedirect()->getResponse();
}
作者:benedicthelfe
项目:translatable-form-fiel
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);
}
作者:WildCodeSchoo
项目:projet-gest
/**
* @param Request $request
* @param Form $form
* @param Eleve $eleve
* @return bool
*/
private function processPostedForm(Request $request, Form $form, Eleve $eleve, Period $periode)
{
$em = $this->getDoctrine()->getManager();
$form->handleRequest($request);
if ($form->isValid()) {
$temporary_taps_to_persist = $eleve->getTaps();
// retire toutes les inscriptions au TAP pour la période qui ne sont pas
// et qui n'ont pas été enregistré par le parent
// dans la nouvelle sélection
$repo = $em->getRepository('WCSCantineBundle:Eleve');
$eleve_taps_periode = $repo->findAllTapsForPeriode($eleve, $periode, true);
foreach ($eleve_taps_periode as $item) {
if (!$temporary_taps_to_persist->contains($item)) {
$em->remove($item);
}
}
// retire toutes les inscriptions à la garderie pour la période qui ne sont pas
// et qui n'ont pas été enregistré par le parent
// dans la nouvelle sélection
$temporary_garderies_to_persist = $eleve->getGarderies();
$eleve_garderies_periode = $repo->findAllGarderiesForPeriode($eleve, $periode, true);
foreach ($eleve_garderies_periode as $item) {
if (!$temporary_garderies_to_persist->contains($item)) {
$em->remove($item);
}
}
$eleve->setTapgarderieSigned(true);
$em->flush();
return true;
}
return false;
}
作者:jaapjansm
项目:homefinanc
/**
* @param Form $form
* @param RuleAction $action
* @return void
*/
public function formIsSubmitted(Form $form, RuleAction $action)
{
$params = $this->getParams($action);
$category = $form->get('category')->getData();
$params['category_id'] = $category->getId();
$action->setRawParams($params);
}
作者:rsantella
项目:bunnies-kinder
public function saveCobroForm(Form $form, Cobro $cobro, $cuentaId)
{
$cuenta = $this->em->getRepository('AppBundle:Cuenta')->find($cuentaId);
$result = false;
$message = 'Ocurrion un error al guardar el cobro.';
$amount = 0;
$positive = false;
if ($cuenta && $form->isValid()) {
$cobro->setCuenta($cuenta);
$this->em->persist($cobro);
$cuenta->addPagoAmount($cobro->getMonto());
$this->em->persist($cuenta);
$this->em->flush();
$result = true;
$message = 'Cobro guardado con exito.';
if ($cobro->getEnviado()) {
//send email
$message .= ' Email enviado correctamente';
}
$amount = $cuenta->getFormatedDiferencia();
if ($cuenta->getDiferencia() < 0) {
$positive = true;
}
}
return array('result' => $result, 'message' => $message, 'amount' => $amount, 'positive' => $positive, 'cuentaId' => $cuentaId, 'cobro' => $cobro);
}
作者:hafeez300
项目:liches
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;
}
作者:dark-b
项目:mdtgeneratorbundl
/**
* Get rid on any fields that don't appear in the form
*
* @param Request $request
* @param Form $form
*/
protected function removeExtraFields(Request $request, Form $form)
{
$data = $request->request->all();
$children = $form->all();
$data = array_intersect_key($data, $children);
$request->request->replace($data);
}
作者:farido
项目:ServerGroveLiveCha
private function createLoginForm($operator = null)
{
$form = new Form('login', array('validator' => $this->get('validator')));
$form->add(new TextField('email'));
$form->add(new PasswordField('passwd'));
return $form;
}
作者:ahmadrabi
项目:Syliu
function it_does_not_remove_user_form_type_if_users_data_is_submitted(FormEvent $event, Form $form)
{
$event->getData()->willReturn(['user' => ['plainPassword' => 'test']]);
$event->getForm()->shouldNotBeCalled();
$form->remove('user')->shouldNotBeCalled();
$this->preSubmit($event);
}
作者:7rin
项目:BigfootCoreBundl
/**
* @param array $data
* @param Form $form
* @return string
*/
protected function aggregatePluralValues(&$data, $form)
{
$labelManager = $this->labelManager;
$labelValue = '';
$standardRules = array();
$explicitRules = array();
foreach ($data as $property => $value) {
if (0 === strpos($property, self::PLURAL_FIELD_PREFIX)) {
$pluralForm = substr($property, strlen(self::PLURAL_FIELD_PREFIX));
if (is_numeric($pluralForm)) {
$standardRules[$pluralForm] = $value;
} else {
$explicitRules[$pluralForm] = sprintf('%s %s', $labelManager->reverseTransformInterval($pluralForm), $value);
}
$form->remove($property);
unset($data[$property]);
}
}
if ($standardRules) {
$labelValue = implode('|', $standardRules);
if ($explicitRules) {
$labelValue .= '|' . implode('|', $explicitRules);
}
} elseif ($explicitRules) {
$labelValue = implode('|', $explicitRules);
}
return $labelValue;
}
作者:jarmas861
项目:proyec
/**
* This method is here to make your life better, so overwrite it
*
* @param \Symfony\Component\Form\Form $form the valid form
* @param \Taskeet\MainBundle\Entity\Event $Event your \Taskeet\MainBundle\Entity\Event object
*/
public function preSave(\Symfony\Component\Form\Form $form, \Taskeet\MainBundle\Entity\Event $Event)
{
if (!$form->get('reminder')->getData() instanceof DateTime && $form->get('reminder')->getData()) {
$date = clone $form->get('startDate')->getData();
$date->sub(new DateInterval($form->get('reminder')->getData()));
$Event->setReminder($date);
}
}
作者:Kid-Binar
项目:FR
public function stringifyFormErrors(Form $form)
{
$errors = [];
foreach ($form->getErrors(true, true) as $error) {
$errors[] = $error->getMessage();
}
return implode('<br>', $errors);
}
作者:WildCodeSchoo
项目:projet-gest
/**
* @param Request $request
* @param Form $form
* @param Eleve $eleve
* @return bool
*/
private function processPostedForm(Request $request, Form $form, Eleve $eleve)
{
$em = $this->getDoctrine()->getManager();
$form->handleRequest($request);
if ($form->isValid()) {
// la nouvelle sélection de dates (avec celles déjà présentes en
// base de données, et les nouvelles à ajouter
// (cette liste a été mise à jour avec LunchToStringTransformer)
$lunchesNew = $eleve->getLunches();
// récupère les réservations actuellement en base de données
$lunchesOld = $em->getRepository("WCSCantineBundle:Lunch")->findByEleve($eleve);
// supprime les dates qui ne sont plus sélectionnées
foreach ($lunchesOld as $lunchOld) {
if (!$lunchesNew->contains($lunchOld)) {
$em->remove($lunchOld);
}
}
$eleve->setCanteenSigned(true);
// met à jour la fiche élève (le régime alimentaire,...)
$em->persist($eleve);
$em->flush();
return true;
}
return false;
}
作者:alexander-schran
项目:sulu-website-user-bundl
/**
* {@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;
}
作者:kegan
项目:rock-paper-scissors-spock-lizard-gam
private function getErrorMessages(Form $form)
{
$errors = [];
foreach ($form->getErrors(true, true) as $key => $error) {
$errors[] = $error->getMessage();
}
return $errors;
}