public function preSetData(FormEvent $event) { $data = $event->getData(); $form = $event->getForm(); $estado = ($data and $data->getEstado()) ? $data->getEstado() : null; $this->addField($form, $estado); }
/** * Reorder the children of the parent form data at $this->name. * * For whatever reason we have to go through the parent object, just * getting the collection from the form event and reordering it does * not update the stored order. * * @param FormEvent $event */ public function onSubmit(FormEvent $event) { $form = $event->getForm()->getParent(); $data = $form->getData(); if (!is_object($data)) { return; } $accessor = PropertyAccess::getPropertyAccessor(); // use deprecated BC method to support symfony 2.2 $newCollection = $accessor->getValue($data, $this->name); if (!$newCollection instanceof Collection) { return; } /* @var $newCollection Collection */ $newCollection->clear(); /** @var $item FormBuilder */ foreach ($form->get($this->name) as $key => $item) { if ($item->get('_delete')->getData()) { // do not re-add a deleted child continue; } if ($item->getName() && !is_numeric($item->getName())) { // keep key in collection $newCollection[$item->getName()] = $item->getData(); } else { $newCollection[] = $item->getData(); } } }
public function submit(FormEvent $event) { $entity = $event->getData(); if (!empty($entity) && $entity->isLocked()) { $event->getForm()->addError(new FormError('error.element_locked')); } }
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); }
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); }
public function preSetData(FormEvent $event) { $form = $event->getForm(); $form->add('customData', CustomFormType::class, ['callback' => function (FormBuilderInterface $builder) { return $this->customFormModel->constructForm($builder); }, 'validationCallback' => 'validateForm']); }
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); }
public function preSubmit(FormEvent $event) { $data = $event->getData(); $form = $event->getForm(); $country_id = array_key_exists('country', $data) ? $data['country'] : null; $this->addProvinceForm($form, $country_id); }
/** * PRE_SET_DATA event handler * * @param FormEvent $event */ public function preSetData(FormEvent $event) { $form = $event->getForm(); if ($this->calendarConfig->isPublicCalendarEnabled() && $this->calendarConfig->isSystemCalendarEnabled()) { $options = ['required' => false, 'label' => 'oro.calendar.systemcalendar.public.label', 'empty_value' => false, 'choices' => [false => 'oro.calendar.systemcalendar.scope.organization', true => 'oro.calendar.systemcalendar.scope.system']]; /** @var SystemCalendar|null $data */ $data = $event->getData(); if ($data) { $isPublicGranted = $this->securityFacade->isGranted('oro_public_calendar_management'); $isSystemGranted = $this->securityFacade->isGranted($data->getId() ? 'oro_system_calendar_update' : 'oro_system_calendar_create'); if (!$isPublicGranted || !$isSystemGranted) { $options['read_only'] = true; if (!$data->getId() && !$isSystemGranted) { $options['data'] = true; } unset($options['choices'][$isSystemGranted]); } } $form->add('public', 'choice', $options); } elseif ($this->calendarConfig->isPublicCalendarEnabled()) { $form->add('public', 'hidden', ['data' => true]); } elseif ($this->calendarConfig->isSystemCalendarEnabled()) { $form->add('public', 'hidden', ['data' => false]); } }
/** * @param FormEvent $event */ public function postBind(FormEvent $event) { $product = $event->getData(); $thumbnail = ''; $first = false; foreach ($product->getImages() as $image) { if (!$first) { $thumbnail = $image->getPath(); $first = true; } if ($image->getThumb()) { $thumbnail = $image->getPath(); } $image->setProduct($product); $this->container->get('product_manager')->save($image, false); } $product->setThumbnail($thumbnail); if (null !== $product->getId()) { $imageDir = $this->container->get('kernel')->getRootDir() . '/../web/uploads/products/'; $imgList = $this->container->get('product_image_manager')->getRepository()->findBy(array('product' => $product->getId())); foreach ($imgList as $image) { if (!$product->getImages()->contains($image)) { if (file_exists($imageDir . $image->getPath())) { unlink($imageDir . $image->getPath()); } $this->container->get('product_manager')->delete($image); } } } }
/** * @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')); } }
/** * @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); }
public function preBind(FormEvent $event) { $value = $event->getData(); if (is_array($value)) { $event->setData(implode($this->delimiter, $value)); } }
/** * @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); } }
public function onPreSetData(FormEvent $event) { $form = $event->getForm(); if (!is_object($this->user) || !$this->user instanceof UserInterface) { $form->add('guest', new GuestType()); } }
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); }
public function onBindData(FormEvent $event) { $advisorCode = $event->getData(); $advisorCode->setCustodian($this->custodian); $advisorCode->setCustodianId($this->custodian->getId()); $advisorCode->setRiaCompany($this->riaCompany); }
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 onPreSetData(FormEvent $event) { $form = $event->getForm(); if ('contact' === $form->getName()) { $form->add('sample_form', 'text'); } }
public function preSetData(FormEvent $event) { $data = $event->getData(); $form = $event->getForm(); // During form creation setData() is called with null as an argument // by the FormBuilder constructor. We're only concerned with when // setData is called with an actual Entity object in it (whether new, // or fetched with Doctrine). This if statement let's us skip right // over the null condition. if (null === $data) { return; } // Check the comment type and presend the required field to enter page/blog post id switch ($data->getCommentType()) { case 'Blog': $form->add($this->factory->createNamed('blogPost', 'entity', null, array('auto_initialize' => false, 'class' => 'BardisCMS\\BlogBundle\\Entity\\Blog', 'property' => 'title', 'expanded' => false, 'multiple' => false, 'label' => 'Select Linked Blog Post', 'attr' => array('class' => 'autoCompleteItems autoCompleteBlogs', 'data-sonata-select2' => 'false'), 'required' => false))); break; /* case 'Page': $form->add($this->factory->createNamed('page', 'entity', null, array('auto_initialize' => false, 'class' => 'BardisCMS\PageBundle\Entity\Page', 'property' => 'title', 'expanded' => false, 'multiple' => false, 'label' => 'Select Linked Page', 'attr' => array('class' => 'autoCompleteItems autoCompletePages', 'data-sonata-select2' => 'false'), 'required' => false))); break; */ /* case 'Page': $form->add($this->factory->createNamed('page', 'entity', null, array('auto_initialize' => false, 'class' => 'BardisCMS\PageBundle\Entity\Page', 'property' => 'title', 'expanded' => false, 'multiple' => false, 'label' => 'Select Linked Page', 'attr' => array('class' => 'autoCompleteItems autoCompletePages', 'data-sonata-select2' => 'false'), 'required' => false))); break; */ default: } }
public function onBind(FormEvent $event) { $data = $event->getData(); if ($this->defaultProtocol && $data && !preg_match('~^\\w+://~', $data)) { $event->setData($this->defaultProtocol . '://' . $data); } }
public function preSetData(FormEvent $event) { $form = $event->getForm(); $data = $event->getData(); if (!$data instanceof $this->dataClass) { return; } //loop over all columns and add the input foreach ($this->columns as $column => $options) { if (is_string($options)) { $column = $options; $options = array(); } if (null === $options) { $options = array(); } $type = 'text'; if (array_key_exists('type', $options)) { $type = $options['type']; } $label = $column; if (array_key_exists('label', $options)) { $label = $options['label']; } $customOptions = array(); if (array_key_exists('options', $options)) { $customOptions = $options['options']; } $options = array('label' => $label . ' ' . strtoupper($data->getLocale())); $options = array_merge($options, $customOptions); $form->add($column, $type, $options); } }
/** * 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); } }
/** * @param FormEvent $event */ public function addFrontendWidgetField(FormEvent $event) { $form = $event->getForm(); $attribute = $event->getData(); $attributeType = ucfirst($attribute->getType()) . 'AttributeType'; $form->add('frontendWidget', 'choice', array('label' => 'Frontend widget', 'choices' => call_user_func(array("Fyb\\Component\\Attribute\\AttributeType\\" . $attributeType, 'getFrontendWidgetChoicesList')))); }
/** * @param FormEvent $event */ public function preSetData(FormEvent $event) { $parentData = $event->getForm()->getParent()->getData(); if ($parentData) { $this->transformer->setAcl($parentData); } }
/** * @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); }
public function preBind(FormEvent $event) { $form = $event->getForm(); $data = $event->getData(); $data = array_replace($this->unbind($form), $data ?: array()); $event->setData($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); }
/** * @param FormEvent $event */ public function preSubmit(FormEvent $event) { $data = $event->getData(); $form = $event->getForm(); $headquartersId = array_key_exists('headquarter', $data) ? $data['headquarter'] : null; $this->addExamForm($form, $headquartersId); }
function it_set_user_as_enabled_if_customer_has_user(FormEvent $event, CustomerInterface $customer, ShopUserInterface $user) { $event->getData()->willReturn($customer); $customer->getUser()->willReturn($user); $user->setEnabled(true)->shouldBeCalled(); $this->submit($event); }