当前位置: 首页>>代码示例>>PHP>>正文


PHP FormEvent::setData方法代码示例

本文整理汇总了PHP中Symfony\Component\Form\FormEvent::setData方法的典型用法代码示例。如果您正苦于以下问题:PHP FormEvent::setData方法的具体用法?PHP FormEvent::setData怎么用?PHP FormEvent::setData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Symfony\Component\Form\FormEvent的用法示例。


在下文中一共展示了FormEvent::setData方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: setData

 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');
     }
 }
开发者ID:EfficiencyNetwork,项目名称:BoltForms,代码行数:8,代码来源:BoltFormsEvent.php

示例2: setData

 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);
     }
 }
开发者ID:rossriley,项目名称:bolt-extension-boltforms,代码行数:8,代码来源:BoltFormsEvent.php

示例3: submit

 public function submit(FormEvent $event)
 {
     $data = $event->getData();
     if (empty($data['entity'])) {
         $event->setData(null);
     } else {
         $event->setData($data['entity']);
     }
 }
开发者ID:xavier-dubreuil,项目名称:EntityModal,代码行数:9,代码来源:EntityModalFormSubscriber.php

示例4: preSubmit

 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));
     }
 }
开发者ID:BusinessCookies,项目名称:CoffeeMachineProject,代码行数:12,代码来源:TrimListener.php

示例5: submit

 /**
  * 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);
     }
 }
开发者ID:P3PO,项目名称:VlabsMediaBundle,代码行数:20,代码来源:BaseFileListener.php

示例6: onPreSubmit

 public function onPreSubmit(FormEvent $event)
 {
     $form = $event->getForm();
     $clientData = $event->getData();
     $clientData = array_replace($this->prepareData($form), $clientData ?: array());
     $event->setData($clientData);
 }
开发者ID:onema,项目名称:base-api-bundle,代码行数:7,代码来源:PatchSubscriber.php

示例7: preSubmitData

 /**
  * @param FormEvent $event
  */
 public function preSubmitData(FormEvent $event)
 {
     $data = $event->getData();
     //clean the data
     $data = InputHelper::_($data, $this->masks);
     $event->setData($data);
 }
开发者ID:dongilbert,项目名称:mautic,代码行数:10,代码来源:CleanFormSubscriber.php

示例8: it_clear_data_if_translatable_and_in_different_locale

 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);
 }
开发者ID:szymach,项目名称:admin-translatable-bundle,代码行数:7,代码来源:TranslatableCollectionListenerSpec.php

示例9: onBind

 public function onBind(FormEvent $event)
 {
     $data = $event->getData();
     if ($this->defaultProtocol && $data && !preg_match('~^\\w+://~', $data)) {
         $event->setData($this->defaultProtocol . '://' . $data);
     }
 }
开发者ID:joan16v,项目名称:symfony2_test,代码行数:7,代码来源:FixUrlProtocolListener.php

示例10: onBind

 /**
  * @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);
 }
开发者ID:kwuerl,项目名称:SonataAdminBundle,代码行数:28,代码来源:MergeCollectionListener.php

示例11:

 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);
 }
开发者ID:okwinza,项目名称:Sylius,代码行数:7,代码来源:AddDefaultBillingAddressOnOrderFormSubscriberSpec.php

示例12: buildCredentials

 /**
  * @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);
 }
开发者ID:Raxer971,项目名称:challenge,代码行数:34,代码来源:GatewayConfigType.php

示例13: submit

 /**
  * Submit listener
  * @param  FormEvent $event
  */
 public function submit(FormEvent $event)
 {
     $image = $event->getData();
     if ($image && $image->isNew() && !$image->hasFile()) {
         $event->setData(null);
     }
 }
开发者ID:fullpipe,项目名称:image-bundle,代码行数:11,代码来源:BuildImageFormListener.php

示例14: move

 /**
  * @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);
     }
 }
开发者ID:leapt,项目名称:admin-bundle,代码行数:38,代码来源:MultiUploadSubscriber.php

示例15: preSubmit

 /**
  * 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);
 }
开发者ID:dairdr,项目名称:crm,代码行数:32,代码来源:SoapSettingsFormSubscriber.php


注:本文中的Symfony\Component\Form\FormEvent::setData方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。