/**
  * {@inheritdoc}
  */
 public function buildView(FormView $view, FormInterface $form, array $options)
 {
     $data = $form->getData();
     if (empty($data)) {
         $form->setData(array('left' => 0, 'top' => 0, 'width' => $options['width'], 'height' => $options['height'], 'min_width' => $options['width'], 'min_height' => $options['height']));
     }
 }
示例#2
0
 public function buildView(FormView $view, FormInterface $form, array $options)
 {
     $center = new GMapsCoordinate($form->getData()->getLatitude(), $form->getData()->getLongitude());
     $this->map->setCenter($center);
     $this->map->setMapOption('zoom', 10);
     $view->vars['map'] = $this->map;
 }
示例#3
0
 public function buildView(FormView $view, FormInterface $form, array $options)
 {
     $view->vars['object'] = $form->getData();
     if ($options['download_link'] && $view->vars['object']) {
         $view->vars['download_uri'] = $this->storage->resolveUri($form->getData(), 'file');
     }
 }
 /**
  * Prepare & process form
  *
  * @author Jeremie Samson <*****@*****.**>
  *
  * @return bool
  */
 public function process()
 {
     if ($this->request->isMethod('POST')) {
         $this->form->handleRequest($this->request);
         if ($this->form->isValid()) {
             /** @var ModelUserRole $model */
             $model = $this->form->getData();
             if (!$model->getUser() || !$model->getRole()) {
                 $this->form->addError(new FormError('Missing parameter(s)'));
             }
             /** @var User $user */
             $user = $this->em->getRepository('UserBundle:User')->find($model->getUser());
             /** @var Post $role */
             $role = $this->em->getRepository('FaucondorBundle:Post')->find($model->getRole());
             if (!$user) {
                 $this->form->get('user')->addError(new FormError('User with id ' . $model->getUser() . ' not found '));
             }
             if (!$role) {
                 $this->form->get('role')->addError(new FormError('Role with id ' . $model->getRole() . ' not found '));
             }
             $this->onSuccess($user, $role);
             return true;
         }
     }
     return false;
 }
示例#5
0
 /**
  * {@inheritdoc}
  */
 public function buildView(FormView $view, FormInterface $form, array $options)
 {
     $vars = ['configs' => $options['configs']];
     if ($form->getData()) {
         $data = $form->getParent()->getData();
         $fieldConfig = $this->cm->getProvider('extend')->getConfig($data, $form->getName());
         if ($form->getData()) {
             /** @var ConverterInterface|EntitySelectHandler $converter */
             $converter = $options['converter'];
             $result = [];
             if ($converter instanceof EntitySelectHandler) {
                 $converter->initForEntity($fieldConfig->getId()->getClassName(), $fieldConfig->get('target_field'));
             }
             if (isset($options['configs']['multiple']) && $options['configs']['multiple']) {
                 foreach ($form->getData() as $item) {
                     $result[] = $converter->convertItem($item);
                 }
             } else {
                 $result[] = $converter->convertItem($form->getData());
             }
             $vars['attr'] = ['data-selected-data' => json_encode($result)];
         }
     }
     $view->vars = array_replace_recursive($view->vars, $vars);
 }
 /**
  * Prepare & process form
  *
  * @author Jeremie Samson <*****@*****.**>
  *
  * @return bool
  */
 public function process()
 {
     if ($this->request->isMethod('POST')) {
         $this->form->handleRequest($this->request);
         if ($this->form->isValid()) {
             /** @var ModelUser $user */
             $user = $this->form->getData();
             if (!$user->getFirstname() || !$user->getLastname() || !$user->getEmailGalaxy() || !$user->getSection()) {
                 $this->form->addError(new FormError('Missing parameter(s)'));
             } else {
                 if (!filter_var($user->getEmail(), FILTER_VALIDATE_EMAIL) || !filter_var($user->getEmailGalaxy(), FILTER_VALIDATE_EMAIL)) {
                     $error = new FormError('email invalid');
                     if (!filter_var($user->getEmail(), FILTER_VALIDATE_EMAIL)) {
                         $this->form->get('email')->addError($error);
                     }
                     if (!filter_var($user->getEmailGalaxy(), FILTER_VALIDATE_EMAIL)) {
                         $this->form->get('emailGalaxy')->addError($error);
                     }
                 } else {
                     $section_id = $this->em->getRepository('FaucondorBundle:Section')->find($user->getSection());
                     $section_code = $this->em->getRepository('FaucondorBundle:Section')->findOneBy(array("code" => $user->getSection()));
                     if (!$section_id && !$section_code) {
                         $this->form->get('section')->addError(new FormError('Section with id ' . $user->getSection() . ' not found'));
                     } else {
                         /** @var Section $section */
                         $section = $section_id ? $section_id : $section_code;
                         $this->onSuccess($user, $section);
                         return true;
                     }
                 }
             }
         }
     }
     return false;
 }
示例#7
0
 /**
  * {@inheritdoc}
  */
 public function extractSubmittedData(FormInterface $form)
 {
     $data = array('submitted_data' => array('norm' => $this->valueExporter->exportValue($form->getNormData())), 'errors' => array());
     if ($form->getViewData() !== $form->getNormData()) {
         $data['submitted_data']['view'] = $this->valueExporter->exportValue($form->getViewData());
     }
     if ($form->getData() !== $form->getNormData()) {
         $data['submitted_data']['model'] = $this->valueExporter->exportValue($form->getData());
     }
     foreach ($form->getErrors() as $error) {
         $errorData = array('message' => $error->getMessage(), 'origin' => is_object($error->getOrigin()) ? spl_object_hash($error->getOrigin()) : null, 'trace' => array());
         $cause = $error->getCause();
         while (null !== $cause) {
             if ($cause instanceof ConstraintViolationInterface) {
                 $errorData['trace'][] = array('class' => $this->valueExporter->exportValue(get_class($cause)), 'root' => $this->valueExporter->exportValue($cause->getRoot()), 'path' => $this->valueExporter->exportValue($cause->getPropertyPath()), 'value' => $this->valueExporter->exportValue($cause->getInvalidValue()));
                 $cause = method_exists($cause, 'getCause') ? $cause->getCause() : null;
                 continue;
             }
             if ($cause instanceof \Exception) {
                 $errorData['trace'][] = array('class' => $this->valueExporter->exportValue(get_class($cause)), 'message' => $this->valueExporter->exportValue($cause->getMessage()));
                 $cause = $cause->getPrevious();
                 continue;
             }
             $errorData['trace'][] = $cause;
             break;
         }
         $data['errors'][] = $errorData;
     }
     $data['synchronized'] = $this->valueExporter->exportValue($form->isSynchronized());
     return $data;
 }
 /**
  * {@inheritdoc}
  */
 public function buildView(FormView $view, FormInterface $form, array $options)
 {
     if ($form->getData() instanceof ProductValueInterface) {
         $this->productFormView->addChildren($form->getData(), $view);
     }
     $view->vars['mode'] = isset($options['block_config']['mode']) ? $options['block_config']['mode'] : 'normal';
 }
示例#9
0
 /**
  * {@inheritdoc}
  */
 public function getData()
 {
     $data = array('form' => $this->form->createView(), 'element' => $this->element);
     if ($this->form->getData()) {
         $data['id'] = $this->element->getDataIndexer()->getIndex($this->form->getData());
     }
     return $data;
 }
 /**
  * Get resource node.
  */
 private function getResourceNode(FormInterface $form)
 {
     if ($form->getData() instanceof ResourceNode) {
         return $form->getData();
     } elseif ($form->getData() && $form->getData() != '') {
         return $this->resourceManager->getById($form->getData());
     }
 }
 /**
  * @param FormInterface $form
  * @param Request       $request
  * @param array         $options
  *
  * @return bool
  */
 public function handle(FormInterface $form, Request $request, array $options = null)
 {
     $form->handleRequest($request);
     if (!$form->isValid()) {
         return false;
     }
     $this->handler->updateCredentials($form->getData()->getUser(), $form->getData()->getNewPassword());
     return true;
 }
示例#12
0
 /**
  * @dataProvider getInvalidInputs
  */
 public function testErrorSubmit($submitted, $expected, array $invalidFields = [])
 {
     $this->sut->submit($submitted);
     $this->assertFalse($this->sut->isValid());
     foreach ($invalidFields as $child) {
         $this->assertFalse($this->sut->get($child)->isValid(), "{$child} isValid");
     }
     $this->assertEquals($expected, $this->sut->getData());
 }
 /**
  * {@inheritdoc}
  */
 public function buildView(FormView $view, FormInterface $form, array $options)
 {
     $vars = array('configs' => $options['configs']);
     if ($form->getData()) {
         $fieldConfig = $this->entityManager->getExtendManager()->getConfigProvider()->getConfig($form->getParent()->getData(), $form->getName());
         $fieldName = $fieldConfig->get('target_field');
         $vars['attr'] = array('data-entities' => json_encode(array(array($fieldName => $form->getData()->{'get' . ucfirst($fieldName)}()))));
     }
     $view->vars = array_replace_recursive($view->vars, $vars);
 }
 /**
  * @param Quote $quote
  * @return Order|null
  */
 public function process(Quote $quote)
 {
     $this->form->setData($quote);
     if ($this->request->isMethod('POST')) {
         $this->form->submit($this->request);
         if ($this->form->isValid()) {
             return $this->onSuccess($quote, $this->form->getData());
         }
     }
     return null;
 }
 public function buildView(FormView $view, FormInterface $form, array $options)
 {
     $filename = $options['image_filename'] ?: (!is_null($form->getData()) ? $form->getData()->getHGFile()->getFilOriginalFilename() : '');
     $size = $this->fileManager->sizeExistsForType($options['repository_type'], $options['image_preview_size']) ? $options['image_preview_size'] : null;
     $view->vars['image_filename'] = $filename;
     $view->vars['delete_link_class'] = $options['delete_link_class'];
     $view->vars['delete_link_type'] = $options['delete_link_type'];
     $view->vars['delete_link_text'] = $options['delete_link_text'];
     $view->vars['image_preview_class'] = $options['image_preview_class'];
     $view->vars['image_preview_size'] = $size;
     $view->vars['template'] = $options['template'];
 }
 public function buildView(FormView $view, FormInterface $form, array $options)
 {
     $filename = $options['download_filename'] ?: (!is_null($form->getData()) ? $form->getData()->getFilOriginalFilename() : '');
     $view->vars['download_filename'] = $filename;
     $view->vars['delete_link_class'] = $options['delete_link_class'];
     $view->vars['delete_link_type'] = $options['delete_link_type'];
     $view->vars['delete_link_text'] = $options['delete_link_text'];
     $view->vars['download_link_class'] = $options['download_link_class'];
     $view->vars['download_link_text'] = $options['download_link_text'];
     $view->vars['template'] = $options['template'];
     $view->vars['download_route'] = $options['download_route'];
 }
 /**
  * @param  Request      $request
  * @return JsonResponse
  */
 public function uploadComposerAction(Request $request)
 {
     $this->composerForm->handleRequest($request);
     if ($this->composerForm->isValid()) {
         $data = $this->composerForm->getData();
         $this->sonataNotificationsBackend->createAndPublish('upload.composer', array('body' => $data['body'], 'channelName' => $request->getSession()->get('channelName'), 'hasDevDependencies' => $data['hasDevDependencies']));
         return new JsonResponse(array('status' => 'ok'));
     }
     $errors = array_map(function (FormError $error) {
         return $error->getMessage();
     }, $this->composerForm->get('body')->getErrors());
     return new JsonResponse(array('status' => 'ko', 'message' => $errors));
 }
示例#18
0
 public function testValidSubmit()
 {
     $submitted = ['nickname' => 'daenerys-targa-7', 'gender' => 'xx', 'dateOfBirth' => ['year' => 1986, 'month' => 11, 'day' => 13]];
     $this->sut->submit($submitted);
     $this->assertTrue($this->sut->isValid());
     $user = $this->sut->getData();
     $this->assertInstanceOf('Trismegiste\\SocialBundle\\Security\\Netizen', $user);
     $this->assertEquals('daenerys-targa-7', $user->getUsername());
     $this->assertEquals('xx', $user->getProfile()->gender);
     $this->assertNotEmpty($user->getCredential());
     $this->assertEquals('dummy', $user->getCredential()->getProviderKey());
     $this->assertEquals('123456789', $user->getCredential()->getUid());
 }
 public function mapFormToData(FormInterface $form, &$data)
 {
     if ($form->getAttribute('property_path') !== null && $form->isSynchronized()) {
         $propertyPath = $form->getAttribute('property_path');
         // If the data is identical to the value in $data, we are
         // dealing with a reference
         $isReference = $form->getData() === $propertyPath->getValue($data);
         $byReference = $form->getAttribute('by_reference');
         if (!(is_object($data) && $isReference && $byReference)) {
             $propertyPath->setValue($data, $form->getData());
         }
     }
 }
 public function changePasswordAction(Request $request)
 {
     $this->changePasswordForm->handleRequest($request);
     if ($this->changePasswordForm->isValid()) {
         $user = $this->tokenStorage->getToken()->getUser();
         $formData = $this->changePasswordForm->getData();
         $this->eventDispatcher->dispatch(AdminSecurityEvents::CHANGE_PASSWORD, new ChangePasswordEvent($user, $formData['plainPassword']));
         $request->getSession()->invalidate();
         $this->tokenStorage->setToken(null);
         $request->getSession()->getFlashBag()->set('success', 'admin.change_password_message.success');
         return new RedirectResponse($this->router->generate('fsi_admin_security_user_login'));
     }
     return $this->templating->renderResponse($this->changePasswordActionTemplate, array('form' => $this->changePasswordForm->createView()));
 }
示例#21
0
 /**
  * {@inheritdoc}
  */
 public function extractSubmittedData(FormInterface $form)
 {
     $data = array('submitted_data' => array('norm' => $this->valueExporter->exportValue($form->getNormData())), 'errors' => array());
     if ($form->getViewData() !== $form->getNormData()) {
         $data['submitted_data']['view'] = $this->valueExporter->exportValue($form->getViewData());
     }
     if ($form->getData() !== $form->getNormData()) {
         $data['submitted_data']['model'] = $this->valueExporter->exportValue($form->getData());
     }
     foreach ($form->getErrors() as $error) {
         $data['errors'][] = array('message' => $error->getMessage());
     }
     $data['synchronized'] = $this->valueExporter->exportValue($form->isSynchronized());
     return $data;
 }
 /**
  * Validates the data of a form
  *
  * This method is called automatically during the validation process.
  *
  * @param FormInterface    $form    The validated form
  * @param ExecutionContext $context The current validation context
  */
 public static function validateFormData(FormInterface $form, ExecutionContext $context)
 {
     if (is_object($form->getData()) || is_array($form->getData())) {
         $propertyPath = $context->getPropertyPath();
         $graphWalker = $context->getGraphWalker();
         // Adjust the property path accordingly
         if (!empty($propertyPath)) {
             $propertyPath .= '.';
         }
         $propertyPath .= 'data';
         foreach (self::getFormValidationGroups($form) as $group) {
             $graphWalker->walkReference($form->getData(), $group, $propertyPath, true);
         }
     }
 }
示例#23
0
 /**
  * @param FormInterface $form
  * @return int|false ID of inserted data OR success
  */
 public function registerUser(FormInterface $form)
 {
     if ($this->encoder == null) {
         throw new \Exception("Encoder can not be NULL! Do you added the Encoder by using add_encoder() ??");
     }
     if ($form->isValid()) {
         $data = $form->getData();
         $entity = new GBUserEntry();
         $entity->setNick($data['nick']);
         $entity->setPass($this->encodePassword($entity, $data['password']));
         try {
             $this->emanager->persist($entity);
             $this->emanager->flush();
             return $entity->getUid();
         } catch (\Exception $ex) {
             $this->errormessage = $ex->getMessage();
             if (strstr($this->errormessage, "Duplicate")) {
                 $this->errormessage = "Dieser Nick wird bereits verwendet!";
             }
             return false;
         }
     } elseif ($form->isSubmitted()) {
         $this->errormessage = (string) $form->getErrors(true);
     }
     return false;
 }
 /**
  * @param FormView $view
  * @param FormInterface $form
  * @param array $options
  */
 public function buildView(FormView $view, FormInterface $form, array $options)
 {
     /** @var ProductionPlanEditDTO $data */
     $data = $form->getData();
     $view->vars['dateString'] = $data->dateString;
     $view->vars['workingShiftsDisplayNames'] = $data->workingShiftsDisplayNames;
 }
示例#25
0
 /**
  * @param Request       $request
  * @param FormInterface $form
  * @param GameDetailDto $game
  * @param PlayerDto     $player
  *
  * @return Response|null
  */
 private function handlePlayerForm(Request $request, FormInterface $form, GameDetail $game, Player $player)
 {
     $form->handleRequest($request);
     if ($form->isSubmitted() && $form->isValid()) {
         if ($form->get('play')->isClicked()) {
             $turnNumber = $form->getData()->getTurnNumber();
             $move = $form->getData()->getMove();
             if ($move && $move->isPlay()) {
                 $play = new Play($turnNumber, new Stone($move->getStoneTopValue(), $move->getStoneBottomValue()), $move->getSide() === 'left' ? Play::SIDE_LEFT : Play::SIDE_RIGHT);
                 $this->gameService->play($game->getId(), $player->getNumber(), $play);
                 return $this->redirectToRoute(self::ROUTE_PLAYER_DETAIL, ['gameId' => $form->getData()->getGameId(), 'playerNumber' => $form->getData()->getPlayerNumber()]);
             }
         }
     }
     return;
 }
 /**
  * @param \Symfony\Component\Form\FormView $view
  * @param \Symfony\Component\Form\FormInterface $form
  */
 public function buildView(FormView $view, FormInterface $form)
 {
     $sonataAdmin = $form->getAttribute('sonata_admin');
     // avoid to add extra information not required by non admin field
     if ($form->getAttribute('sonata_admin_enabled', true)) {
         $sonataAdmin['value'] = $form->getData();
         // add a new block types, so the Admin Form element can be tweaked based on the admin code
         $types = $view->get('types');
         $baseName = str_replace('.', '_', $sonataAdmin['field_description']->getAdmin()->getCode());
         $baseType = $types[count($types) - 1];
         $types[] = sprintf('%s_%s', $baseName, $baseType);
         $types[] = sprintf('%s_%s_%s', $baseName, $sonataAdmin['field_description']->getName(), $baseType);
         if ($sonataAdmin['block_name']) {
             $types[] = $sonataAdmin['block_name'];
         }
         $view->set('types', $types);
         $view->set('sonata_admin_enabled', true);
         $view->set('sonata_admin', $sonataAdmin);
         $attr = $view->get('attr', array());
         if (!isset($attr['class'])) {
             $attr['class'] = $sonataAdmin['class'];
         }
         $view->set('attr', $attr);
     } else {
         $view->set('sonata_admin_enabled', false);
     }
     $view->set('sonata_admin', $sonataAdmin);
 }
 /**
  * {@inheritdoc}
  */
 public function process(FormInterface $form, Request $request)
 {
     $valid = false;
     if ($request->isMethod('POST')) {
         $form->handleRequest($request);
         if ($form->isValid()) {
             $transUnit = $form->getData();
             $translations = $transUnit->filterNotBlankTranslations();
             // only keep translations with a content
             // link new translations to a file to be able to export them.
             foreach ($translations as $translation) {
                 if (!$translation->getFile()) {
                     $file = $this->fileManager->getFor(sprintf('%s.%s.yml', $transUnit->getDomain(), $translation->getLocale()), $this->rootDir . '/Resources/translations');
                     if ($file instanceof FileInterface) {
                         $translation->setFile($file);
                     }
                 }
             }
             if ($transUnit instanceof PropelTransUnit) {
                 // The setTranslations() method only accepts PropelCollections
                 $translations = new \PropelObjectCollection($translations);
             }
             $transUnit->setTranslations($translations);
             $this->storage->persist($transUnit);
             $this->storage->flush();
             $valid = true;
         }
     }
     return $valid;
 }
示例#28
0
 /**
  * @param \Symfony\Component\Form\FormView $view
  * @param \Symfony\Component\Form\FormInterface $form
  * @param array $options
  * @throws \Symfony\Component\OptionsResolver\Exception\MissingOptionsException
  */
 public function buildView(FormView $view, FormInterface $form, array $options)
 {
     $value = $form->getData();
     // For multiple autocomplete, we need to store textual values indexed by value, along with the prototype
     if ($options['multiple']) {
         // Fix: If $value is null we must cast it as an array
         if (null === $value) {
             $value = [];
         }
         $textValues = [];
         foreach ($value as $entity) {
             $textValues[$entity->getId()] = $this->buildTextValue($entity, $options);
         }
         $view->vars['text_values'] = $textValues;
         $view->vars['prototype'] = $form->getConfig()->getAttribute('prototype')->createView($view);
     } else {
         $textValue = $this->buildTextValue($value, $options);
         $view->vars['text_value'] = $textValue;
     }
     // Set the other variables
     $view->vars['multiple'] = $options['multiple'];
     $view->vars['list_url'] = $this->generateListUrl($options);
     $view->vars['allow_add'] = $options['allow_add'];
     if ($options['allow_add']) {
         $view->vars['add_url'] = $this->generateAddUrl($options);
         $view->vars['add_label'] = $options['add_label'];
     }
 }
示例#29
0
 public function testSubmitFromZenToHan()
 {
     $input = array('tel' => array('tel01' => '12345', 'tel02' => '12345', 'tel03' => '67890'));
     $output = array('tel01' => '12345', 'tel02' => '12345', 'tel03' => '67890');
     $this->form->submit($input);
     $this->assertEquals($output, $this->form->getData());
 }
示例#30
0
 /**
  * ひらがな入力されてもカタカナで返す
  */
 public function testSubmitFromHiraganaToKana()
 {
     $input = array('kana' => array('kana01' => 'ひらがな', 'kana02' => 'にゅうりょく'));
     $output = array('kana01' => 'ヒラガナ', 'kana02' => 'ニュウリョク');
     $this->form->submit($input);
     $this->assertEquals($output, $this->form->getData());
 }