本文整理汇总了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');
}
}
示例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);
}
}
示例3: submit
public function submit(FormEvent $event)
{
$data = $event->getData();
if (empty($data['entity'])) {
$event->setData(null);
} else {
$event->setData($data['entity']);
}
}
示例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));
}
}
示例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);
}
}
示例6: onPreSubmit
public function onPreSubmit(FormEvent $event)
{
$form = $event->getForm();
$clientData = $event->getData();
$clientData = array_replace($this->prepareData($form), $clientData ?: array());
$event->setData($clientData);
}
示例7: preSubmitData
/**
* @param FormEvent $event
*/
public function preSubmitData(FormEvent $event)
{
$data = $event->getData();
//clean the data
$data = InputHelper::_($data, $this->masks);
$event->setData($data);
}
示例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);
}
示例9: onBind
public function onBind(FormEvent $event)
{
$data = $event->getData();
if ($this->defaultProtocol && $data && !preg_match('~^\\w+://~', $data)) {
$event->setData($this->defaultProtocol . '://' . $data);
}
}
示例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);
}
示例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);
}
示例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);
}
示例13: submit
/**
* Submit listener
* @param FormEvent $event
*/
public function submit(FormEvent $event)
{
$image = $event->getData();
if ($image && $image->isNew() && !$image->hasFile()) {
$event->setData(null);
}
}
示例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);
}
}
示例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);
}