public function setData($data)
 {
     if ($this->formsEventName === FormEvents::PRE_SUBMIT) {
         $this->event->setData($data);
     } else {
         throw new \RuntimeException(__CLASS__ . '::' . __FUNCTION__ . ' can only be called in BoltFormsEvents::PRE_SUBMIT');
     }
 }
 public function setData($data)
 {
     if ($this->event->getName() == FormEvents::PRE_SUBMIT) {
         $this->event->setData($data);
     } else {
         trigger_error(__CLASS__ . "::" . __FUNCTION__ . " can only be called in BoltFormsEvents::PRE_SUBMIT", E_USER_ERROR);
     }
 }
 public function submit(FormEvent $event)
 {
     $data = $event->getData();
     if (empty($data['entity'])) {
         $event->setData(null);
     } else {
         $event->setData($data['entity']);
     }
 }
 public function preSubmit(FormEvent $event)
 {
     $data = $event->getData();
     if (!is_string($data)) {
         return;
     }
     if (null !== ($result = @preg_replace('/^[\\pZ\\p{Cc}]+|[\\pZ\\p{Cc}]+$/u', '', $data))) {
         $event->setData($result);
     } else {
         $event->setData(trim($data));
     }
 }
 /**
  * Field logic : set actual object in form or handle new file creation
  *
  * @param \Symfony\Component\Form\FormEvent $event
  */
 public function submit(FormEvent $event)
 {
     $form = $event->getForm();
     if ($form->getNormData() instanceof BaseFileInterface && !$event->getData() instanceof UploadedFile) {
         $event->setData($form->getNormData());
     }
     if ($event->getData() instanceof UploadedFile) {
         $handler = $this->handlerManager->getHandler($form->getParent()->getConfig()->getDataClass(), $form->getName());
         $datas = $handler->create($event->getData());
         $event->setData($datas);
     }
     if (is_string($event->getData())) {
         $event->setData(null);
     }
 }
示例#6
0
 public function onPreSubmit(FormEvent $event)
 {
     $form = $event->getForm();
     $clientData = $event->getData();
     $clientData = array_replace($this->prepareData($form), $clientData ?: array());
     $event->setData($clientData);
 }
示例#7
0
 /**
  * @param FormEvent $event
  */
 public function preSubmitData(FormEvent $event)
 {
     $data = $event->getData();
     //clean the data
     $data = InputHelper::_($data, $this->masks);
     $event->setData($data);
 }
 public function it_clear_data_if_translatable_and_in_different_locale(TranslatableFormHelper $translatableFormHelper, FormEvent $event, FormInterface $form, FormInterface $parentForm)
 {
     $translatableFormHelper->isFormPropertyPathTranslatable($form)->willReturn(true);
     $translatableFormHelper->isFormDataInCurrentLocale($parentForm)->willReturn(false);
     $event->setData(Argument::any())->shouldBeCalled();
     $this->onPreSetData($event);
 }
 public function onBind(FormEvent $event)
 {
     $data = $event->getData();
     if ($this->defaultProtocol && $data && !preg_match('~^\\w+://~', $data)) {
         $event->setData($this->defaultProtocol . '://' . $data);
     }
 }
 /**
  * @param \Symfony\Component\Form\FormEvent $event
  */
 public function onBind(FormEvent $event)
 {
     $collection = $event->getForm()->getData();
     $data = $event->getData();
     // looks like there is no way to remove other listeners
     $event->stopPropagation();
     if (!$collection) {
         $collection = $data;
     } elseif (count($data) === 0) {
         $this->modelManager->collectionClear($collection);
     } else {
         // merge $data into $collection
         foreach ($collection as $entity) {
             if (!$this->modelManager->collectionHasElement($data, $entity)) {
                 $this->modelManager->collectionRemoveElement($collection, $entity);
             } else {
                 $this->modelManager->collectionRemoveElement($data, $entity);
             }
         }
         foreach ($data as $entity) {
             $this->modelManager->collectionAddElement($collection, $entity);
         }
     }
     $event->setData($collection);
 }
 function it_does_not_set_default_billing_address_if_different_billing_address_is_requested(FormEvent $event)
 {
     $orderData = ['differentBillingAddress' => true, 'shippingAddress' => ['firstName' => 'Jon', 'lastName' => 'Snow'], 'billingAddress' => ['firstName' => 'Eddard', 'lastName' => 'Stark']];
     $event->getData()->willReturn($orderData);
     $event->setData($orderData)->shouldNotBeCalled();
     $this->preSubmit($event);
 }
示例#12
0
 /**
  * @param FormEvent $event
  */
 public function buildCredentials(FormEvent $event)
 {
     /** @var array $data */
     $data = $event->getData();
     if (is_null($data)) {
         return;
     }
     $propertyPath = is_array($data) ? '[factoryName]' : 'factoryName';
     $factoryName = PropertyAccess::createPropertyAccessor()->getValue($data, $propertyPath);
     if (empty($factoryName)) {
         return;
     }
     $form = $event->getForm();
     $form->add('config', 'form');
     $configForm = $form->get('config');
     $gatewayFactory = $this->registry->getGatewayFactory($factoryName);
     $config = $gatewayFactory->createConfig();
     $propertyPath = is_array($data) ? '[config]' : 'config';
     $firstTime = false == PropertyAccess::createPropertyAccessor()->getValue($data, $propertyPath);
     foreach ($config['payum.default_options'] as $name => $value) {
         $propertyPath = is_array($data) ? "[config][{$name}]" : "config[{$name}]";
         if ($firstTime) {
             PropertyAccess::createPropertyAccessor()->setValue($data, $propertyPath, $value);
         }
         $type = is_bool($value) ? 'checkbox' : 'text';
         $options = array();
         $options['required'] = in_array($name, $config['payum.required_options']);
         $configForm->add($name, $type, $options);
     }
     $event->setData($data);
 }
 /**
  * Submit listener
  * @param  FormEvent $event
  */
 public function submit(FormEvent $event)
 {
     $image = $event->getData();
     if ($image && $image->isNew() && !$image->hasFile()) {
         $event->setData(null);
     }
 }
 /**
  * @param FormEvent $event
  */
 public function move(FormEvent $event)
 {
     $data = $event->getData();
     if (is_callable($this->dstDir)) {
         $dstDir = call_user_func($this->dstDir, $event->getForm()->getParent()->getData());
     } else {
         $dstDir = $this->dstDir;
     }
     if (!empty($data)) {
         foreach ($data as $key => $path) {
             // First check if the file is still in tmp directory
             $originalFilename = $this->rootDir . '/../web/' . trim($path, '/');
             $destinationFilename = $this->rootDir . '/../web/' . trim($dstDir, '/') . '/' . basename($path);
             $webPath = rtrim($dstDir, '/') . '/' . basename($path);
             if (file_exists($originalFilename)) {
                 // if it does, then move it to the destination and update the data
                 $file = new File($originalFilename);
                 $file->move(dirname($destinationFilename));
                 // modify the form data with the new path
                 $data[$key] = $webPath;
             } else {
                 // otherwise check if it is already on the destination
                 if (file_exists($destinationFilename)) {
                     // if it does, simply modify the form data with the new path
                     // modify the form data with the new path
                     $data[$key] = $webPath;
                 } else {
                     // TODO :  check if we need to throw an exception here
                     unset($data[$key]);
                 }
             }
         }
         $event->setData($data);
     }
 }
示例#15
0
 /**
  * Pre submit event listener
  * Encrypt passwords and populate if empty
  * Populate websites choices from hidden fields
  *
  * @param FormEvent $event
  */
 public function preSubmit(FormEvent $event)
 {
     $data = (array) $event->getData();
     $form = $event->getForm();
     $oldPassword = $form->get('apiKey')->getData();
     if (empty($data['apiKey']) && $oldPassword) {
         // populate old password
         $data['apiKey'] = $oldPassword;
     } elseif (isset($data['apiKey'])) {
         $data['apiKey'] = $this->encryptor->encryptData($data['apiKey']);
     }
     // first time all websites comes from frontend(when run sync action)
     // otherwise loaded from entity
     if (!empty($data['websites'])) {
         $websites = $data['websites'];
         // reverseTransform, but not set back to event
         if (!is_array($websites)) {
             $websites = json_decode($websites, true);
         }
         $modifier = $this->getModifierWebsitesList($websites);
         $modifier($form);
     }
     $this->muteFields($form);
     $event->setData($data);
 }
 public function onPreSetData(FormEvent $event)
 {
     $form = $event->getForm();
     $formName = $this->getSessionName($form);
     if ($this->session->has($formName)) {
         $filters = $this->session->get($formName);
         foreach ($filters as $field => &$value) {
             if ($form->has($field)) {
                 $fieldConfig = $form->get($field)->getConfig();
                 $fieldType = $fieldConfig->getType()->getName();
                 switch ($fieldType) {
                     case 'alpixel_entity_id':
                         $entityManager = $fieldConfig->getOption('em');
                         if ($entityManager === null) {
                             $entityManager = $this->entityManager;
                         }
                         $className = $fieldConfig->getOption('class');
                         $value = $entityManager->getRepository($className)->find($value);
                         break;
                     case 'entity':
                         $entityManager = $fieldConfig->getOption('em');
                         $className = $fieldConfig->getOption('class');
                         $value = $entityManager->getRepository($className)->find($value);
                         break;
                     case 'checkbox':
                         $value = (bool) $value;
                         break;
                 }
             }
         }
         $event->setData($filters);
     }
     $form->add('reset', SubmitType::class, ['label' => 'Réinitialiser le formulaire', 'attr' => ['class' => 'btn btn-warning reset-cookie-form-action']]);
 }
 public function preBind(FormEvent $event)
 {
     $value = $event->getData();
     if (is_array($value)) {
         $event->setData(implode($this->delimiter, $value));
     }
 }
 /**
  * @param \Symfony\Component\Form\FormEvent $event
  */
 public function preSubmit(FormEvent $event)
 {
     $data = $event->getData();
     if (empty($data)) {
         $event->setData($event->getForm()->getData());
     }
 }
 /**
  * @param FormEvent $event
  */
 protected function addFormType(FormEvent $event)
 {
     $form = $event->getForm();
     $data = $event->getData();
     $event->setData($data);
     if ($form->has('contentId')) {
         $form->remove('contentId');
     }
     if ($form->has('help-text')) {
         $form->remove('help-text');
     }
     $choices = array();
     if (!is_null($data)) {
         if (array_key_exists('contentType', $data) && $data['contentType'] != '') {
             $choices = array_merge($choices, $this->getChoices($data['contentType'], array_key_exists('choiceType', $data) && $data['choiceType'] != '' ? $data['choiceType'] : ReadContentRepositoryInterface::CHOICE_AND, array_key_exists('keywords', $data) && $data['keywords'] ? $data['keywords'] : null));
         }
         if (array_key_exists('contentId', $data) && $data['contentId'] != '') {
             $choices = array_merge($choices, $this->getChoice($data['contentId']));
         }
     }
     if (count($choices) > 0) {
         $form->add('contentId', 'choice', array('label' => false, 'empty_value' => ' ', 'required' => $this->required, 'choices' => $choices, 'attr' => $this->attributes));
     } else {
         $form->add('contentId', 'hidden', array('required' => $this->required, 'error_mapping' => 'help-text'));
         $form->add('help-text', 'button', array('disabled' => true, 'label' => 'open_orchestra_backoffice.form.content_search.use'));
     }
 }
 public function preBind(FormEvent $event)
 {
     $data = $event->getData();
     $form = $event->getForm();
     $mediaClass = get_class(new Media());
     foreach ($data as $each) {
         $newData[$each['advertisementPropertyName']] = $each;
     }
     foreach ($form->getData() as $i => $each) {
         $property = $each->getAdvertisementPropertyName();
         if (isset($newData[$property->getId()])) {
             if ($property->getName() == 'highlights') {
                 foreach ($each->getValue() as $i => $highlight) {
                     if (!empty($highlight) && isset($newData[$property->getId()]['value']) && isset($newData[$property->getId()]['value'][$i]) && is_null($newData[$property->getId()]['value'][$i]['icon']) && is_object($highlight['icon']) && get_class($highlight['icon']) == $mediaClass) {
                         $newData[$property->getId()]['value'][$i]['icon'] = $highlight['icon'];
                     }
                 }
             }
             if ($property->getName() == 'media_id' && isset($newData[$property->getId()]['value']) && is_null($newData[$property->getId()]['value']) && get_class($each->getValue()) == $mediaClass) {
                 //$newData[$property->getId()]['value'] = $each->getValue()->getId() ? $each->getValue() : '';
                 $newData[$property->getId()]['value'] = $each->getValue();
             }
         }
     }
     $event->setData(array_values($newData));
 }
示例#21
0
 public function preSubmit(FormEvent $event)
 {
     $data = $event->getData();
     if (is_array($data)) {
         // Flip the submitted values for faster lookup
         // It's better to flip this array than $existingValues because
         // $submittedValues is generally smaller.
         $submittedValues = array_flip($data);
         // Since expanded choice fields are completely loaded anyway, we
         // can just as well get the values again without losing performance.
         $existingValues = $this->choiceList->getValues();
         // Clear the data array and fill it with correct indices
         $data = array();
         foreach ($existingValues as $index => $value) {
             if (isset($submittedValues[$value])) {
                 // Value was submitted
                 $data[$index] = $value;
                 unset($submittedValues[$value]);
             }
         }
         if (count($submittedValues) > 0) {
             throw new TransformationFailedException(sprintf('The following choices were not found: "%s"', implode('", "', array_keys($submittedValues))));
         }
     } elseif ('' === $data || null === $data) {
         // Empty values are always accepted.
         $data = array();
     }
     // Else leave the data unchanged to provoke an error during submission
     $event->setData($data);
 }
 public function preSubmitData(FormEvent $event)
 {
     // Sanitize data to avoid XSS attacks
     $data = $event->getData();
     $data = $this->sanitizeFormData($data);
     $event->setData($data);
 }
示例#23
0
 /**
  * Check for translatable values and preSet it on form
  * if have NO translation in translation catalogue return:
  *  - field name (in case of creating new FieldConfigModel)
  *  - empty string (in case of editing FieldConfigModel)
  *
  * @param FormEvent $event
  */
 public function preSetData(FormEvent $event)
 {
     $configModel = $event->getForm()->getConfig()->getOption('config_model');
     $data = $event->getData();
     $dataChanges = false;
     foreach ($this->configManager->getProviders() as $provider) {
         $scope = $provider->getScope();
         if (isset($data[$scope])) {
             $configId = $this->configManager->getConfigIdByModel($configModel, $scope);
             $translatable = $provider->getPropertyConfig()->getTranslatableValues($configId);
             foreach ($data[$scope] as $code => $value) {
                 if (in_array($code, $translatable)) {
                     if ($this->translator->hasTrans($value)) {
                         $data[$scope][$code] = $this->translator->trans($value);
                     } elseif (!$configModel->getId() && $configModel instanceof FieldConfigModel) {
                         $data[$scope][$code] = $configModel->getFieldName();
                     } else {
                         $data[$scope][$code] = '';
                     }
                     $dataChanges = true;
                 }
             }
         }
     }
     if ($dataChanges) {
         $event->setData($data);
     }
 }
 /**
  * @param FormEvent $event
  */
 public function onSubmit(FormEvent $event)
 {
     $data = $event->getData();
     if (is_string($data)) {
         $event->setData($this->converter->convert($data));
     }
 }
示例#25
0
 /**
  * @param FormEvent $event
  */
 public function preBind(FormEvent $event)
 {
     $data = $event->getData();
     $data['slug'] = empty($data['slug']) ? Html::slugify($data['title']) : Html::slugify($data['slug']);
     /* Replacing new value for slug field */
     $event->setData($data);
 }
示例#26
0
 public function preBind(FormEvent $event)
 {
     $data = $event->getData();
     if (is_string($data)) {
         $event->setData(trim($data));
     }
 }
 public function preBind(FormEvent $event)
 {
     $form = $event->getForm();
     $data = $event->getData();
     $data = array_replace($this->unbind($form), $data ?: array());
     $event->setData($data);
 }
 /**
  * Form event - removes file if scheduled.
  * 
  * @param FormEvent $event
  */
 public function submit(FormEvent $event)
 {
     $entity = $event->getData();
     if ($entity instanceof FileInterface && null === $entity->getId() && null === $entity->getHash()) {
         $event->setData(null);
     }
 }
示例#29
0
 public function onPreBind(FormEvent $event)
 {
     $data = $event->getData();
     if (isset($data['is_final_tier']) && $data['is_final_tier']) {
         $data['tier_top'] = Fee::INFINITY;
         $event->setData($data);
     }
 }
示例#30
-1
 public function preSetData(FormEvent $event)
 {
     $data = $event->getData();
     if (isset($this->mapping['preSetData'][$data])) {
         $event->setData($this->mapping['preSetData'][$data]);
     }
 }