本文整理汇总了PHP中Symfony\Component\Form\FormEvent::getData方法的典型用法代码示例。如果您正苦于以下问题:PHP FormEvent::getData方法的具体用法?PHP FormEvent::getData怎么用?PHP FormEvent::getData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Form\FormEvent
的用法示例。
在下文中一共展示了FormEvent::getData方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: preSetData
public function preSetData(FormEvent $event)
{
$data = $event->getData();
$form = $event->getForm();
$estado = ($data and $data->getEstado()) ? $data->getEstado() : null;
$this->addField($form, $estado);
}
示例2: preSubmit
public function preSubmit(FormEvent $event)
{
$data = $event->getData();
$form = $event->getForm();
$province_id = array_key_exists('province', $data) ? $data['province'] : null;
$this->addCityForm($form, $province_id);
}
示例3: submit
public function submit(FormEvent $event)
{
$entity = $event->getData();
if (!empty($entity) && $entity->isLocked()) {
$event->getForm()->addError(new FormError('error.element_locked'));
}
}
示例4: onPreSubmit
public function onPreSubmit(FormEvent $event)
{
$form = $event->getForm();
$data = $event->getData();
$type = $this->app['orm.em']->getRepository(':Property')->find($data['property'])->getDataType();
$this->renderFormType($form, $type);
}
示例5: postSubmit
/**
* @param FormEvent $event
*/
public function postSubmit(FormEvent $event)
{
$accessor = PropertyAccess::createPropertyAccessor();
$format = $accessor->getValue($event->getData(), $this->formatField);
$source = $accessor->getValue($event->getData(), $this->sourceField);
// make sure the listener works with array
$data = $event->getData();
$accessor->setValue($data, $this->targetField, $this->pool->transform($format, $source));
$event->setData($data);
}
示例6: onPreSubmit
/**
* @param FormEvent $event
*/
public function onPreSubmit(FormEvent $event)
{
$data = $event->getData();
$grid = $event->getForm()->getConfig()->getOption('grid');
if (isset($data['reset'])) {
$this->submittedData = $grid->getData();
} else {
$this->submittedData = array_merge($this->filterManager->get($grid), $event->getData());
}
$event->setData($this->submittedData);
}
示例7: onSubmit
/**
* Method called on Form\FormEvents::SUBMIT
* @param Form\FormEvent $event
*/
public function onSubmit(Form\FormEvent $event)
{
$data = $event->getData();
if (false == $data['deliverToDifferent']) {
$data['delivery'] = clone $data['billing'];
$data['delivery']->type = 'delivery';
$data['delivery']->id = 'delivery';
$event->setData($data);
}
$this->validateCountry($event->getForm(), $event->getData());
}
示例8: 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);
}
}
示例9:
function it_adds_payment_methods_choice_to_the_form(FormEvent $event, FormInterface $form, PaymentInterface $payment)
{
$event->getForm()->willReturn($form);
$event->getData()->willReturn($payment);
$form->add('method', Argument::type('string'), ['label' => 'sylius.form.checkout.payment_method', 'subject' => $payment, 'expanded' => true])->shouldBeCalled();
$this->preSetData($event);
}
示例10: onBindData
public function onBindData(FormEvent $event)
{
$advisorCode = $event->getData();
$advisorCode->setCustodian($this->custodian);
$advisorCode->setCustodianId($this->custodian->getId());
$advisorCode->setRiaCompany($this->riaCompany);
}
示例11: 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);
}
示例12: preSubmit
/**
* @param FormEvent $event
*/
public function preSubmit(FormEvent $event)
{
$data = $event->getData();
$form = $event->getForm();
$country = array_key_exists('country', $data) ? $data['country'] : null;
$this->addDiscretionarySpendingForm($form, $country);
}
示例13: 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);
}
示例14: submit
/**
* 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);
}
}
示例15: manageExtraFiltersFields
/**
* @param FormEvent $event
*/
public function manageExtraFiltersFields(FormEvent $event)
{
$data = $event->getData();
$form = $event->getForm()->getParent();
$form->remove('format');
$form->remove('defaultValue');
$eventDefaultValue = null;
switch ($data) {
case DateFilter::class:
$form->remove('multiple');
$form->add('format', ChoiceType::class, ['label' => 'widget_filter.form.date.format.label', 'choices' => ['widget_filter.form.date.format.choices.year.label' => 'year', 'widget_filter.form.date.format.choices.month.label' => 'month', 'widget_filter.form.date.format.choices.day.label' => 'day'], 'choices_as_values' => true, 'attr' => ['data-refreshOnChange' => 'true']]);
$eventDefaultValue = 'victoire.widget_filter.form.date.set_default_value';
break;
case TagFilter::class:
$form->add('multiple', null, ['label' => 'widget_filter.form.multiple.label']);
$eventDefaultValue = 'victoire.widget_filter.form.tag.set_default_value';
break;
case CategoryFilter::class:
$form->add('multiple', null, ['label' => 'widget_filter.form.multiple.label']);
$eventDefaultValue = 'victoire.widget_filter.form.category.set_default_value';
break;
}
if ($eventDefaultValue) {
$defaultValueEvent = new WidgetFilterSetDefaultValueEvent($form, $data);
$this->eventDispatcher->dispatch($eventDefaultValue, $defaultValueEvent);
}
}