public function buildForm(FormBuilderInterface $builder, array $options) { $transformer = new ManyRelatedTransformer($this->doctrineRegistry, $options['entityName']); $viewTransformer = new ArrayToStringTransformer(); $builder->addModelTransformer($transformer); $builder->addViewTransformer($viewTransformer); }
public function buildForm(FormBuilderInterface $builder, array $options) { $format = $options['format']; $pattern = null; $allowedFormatOptionValues = array(\IntlDateFormatter::FULL, \IntlDateFormatter::LONG, \IntlDateFormatter::MEDIUM, \IntlDateFormatter::SHORT); // If $format is not in the allowed options, it's considered as the pattern of the formatter if it is a string if (!in_array($format, $allowedFormatOptionValues, true)) { if (is_string($format)) { $format = self::DEFAULT_FORMAT; $pattern = $options['format']; } else { throw new CreationException('The "format" option must be one of the IntlDateFormatter constants (FULL, LONG, MEDIUM, SHORT) or a string representing a custom pattern'); } } $formatter = new \IntlDateFormatter(\Locale::getDefault(), $format, \IntlDateFormatter::NONE, 'UTC', \IntlDateFormatter::GREGORIAN, $pattern); $formatter->setLenient(false); $builder->addViewTransformer(new DateTimeToLocalizedStringTransformer($options['data_timezone'], $options['user_timezone'], $format, \IntlDateFormatter::NONE, \IntlDateFormatter::GREGORIAN, $pattern)); if ('string' === $options['input']) { $builder->addModelTransformer(new ReversedTransformer(new DateTimeToStringTransformer($options['data_timezone'], $options['data_timezone'], 'Y-m-d'))); } elseif ('timestamp' === $options['input']) { $builder->addModelTransformer(new ReversedTransformer(new DateTimeToTimestampTransformer($options['data_timezone'], $options['data_timezone']))); } elseif ('array' === $options['input']) { $builder->addModelTransformer(new ReversedTransformer(new DateTimeToArrayTransformer($options['data_timezone'], $options['data_timezone'], array('year', 'month', 'day')))); } $builder->setAttribute('date_pattern', $formatter->getPattern()); }
/** * @param FormBuilderInterface $builder * @param array $options * * @throws NotAllowedClassNameException */ public function buildForm(FormBuilderInterface $builder, array $options) { if ($options['is_condition']) { $builder->addModelTransformer($this->conditionToReferenceKeywordTransformer); } else { $builder->addModelTransformer($this->csvToReferenceKeywordTransformer); } }
/** * {@inheritdoc} */ public function buildForm(FormBuilderInterface $builder, array $options) { if (!$options['multiple']) { $builder->addModelTransformer(new ResourceToIdentifierTransformer($this->resourceRepositoryRegistry->get($options['resource']), $options['choice_value'])); } if ($options['multiple']) { $builder->addModelTransformer(new RecursiveTransformer(new ResourceToIdentifierTransformer($this->resourceRepositoryRegistry->get($options['resource']), $options['choice_value'])))->addViewTransformer(new CollectionToStringTransformer(',')); } }
/** * {@inheritdoc} */ public function buildForm(FormBuilderInterface $builder, array $options) { if ($options['multiple']) { $builder->addModelTransformer(new RecursiveTransformer(new ProductTaxonToTaxonTransformer($this->productTaxonFactory))); } if (!$options['multiple']) { $builder->addModelTransformer(new ProductTaxonToTaxonTransformer($this->productTaxonFactory)); } }
/** * {@inheritdoc} */ public function buildForm(FormBuilderInterface $builder, array $options) { $format = $options['format']; $pattern = null; $allowedFormats = array(\IntlDateFormatter::FULL, \IntlDateFormatter::LONG, \IntlDateFormatter::MEDIUM, \IntlDateFormatter::SHORT); // If $format is not in the allowed options, it's considered as the pattern of the formatter if it is a string if (!in_array($format, $allowedFormats, true)) { if (is_string($format)) { $format = self::DEFAULT_FORMAT; $pattern = $options['format']; } else { throw new CreationException('The "format" option must be one of the IntlDateFormatter constants (FULL, LONG, MEDIUM, SHORT) or a string representing a custom pattern'); } } $formatter = new \IntlDateFormatter(\Locale::getDefault(), $format, \IntlDateFormatter::NONE, 'UTC', \IntlDateFormatter::GREGORIAN, $pattern); $formatter->setLenient(false); if ('single_text' === $options['widget']) { $builder->addViewTransformer(new DateTimeToLocalizedStringTransformer($options['data_timezone'], $options['user_timezone'], $format, \IntlDateFormatter::NONE, \IntlDateFormatter::GREGORIAN, $pattern)); } else { $yearOptions = $monthOptions = $dayOptions = array(); if ('choice' === $options['widget']) { if (is_array($options['empty_value'])) { $options['empty_value'] = array_merge(array('year' => null, 'month' => null, 'day' => null), $options['empty_value']); } else { $options['empty_value'] = array('year' => $options['empty_value'], 'month' => $options['empty_value'], 'day' => $options['empty_value']); } $years = $months = $days = array(); foreach ($options['years'] as $year) { $years[$year] = str_pad($year, 4, '0', STR_PAD_LEFT); } foreach ($options['months'] as $month) { $months[$month] = str_pad($month, 2, '0', STR_PAD_LEFT); } foreach ($options['days'] as $day) { $days[$day] = str_pad($day, 2, '0', STR_PAD_LEFT); } // Only pass a subset of the options to children $yearOptions = array('choices' => $years, 'empty_value' => $options['empty_value']['year']); $monthOptions = array('choices' => $this->formatMonths($formatter, $months), 'empty_value' => $options['empty_value']['month']); $dayOptions = array('choices' => $days, 'empty_value' => $options['empty_value']['day']); // Append generic carry-along options foreach (array('required', 'translation_domain') as $passOpt) { $yearOptions[$passOpt] = $monthOptions[$passOpt] = $dayOptions[$passOpt] = $options[$passOpt]; } } $builder->add('year', $options['widget'], $yearOptions)->add('month', $options['widget'], $monthOptions)->add('day', $options['widget'], $dayOptions)->addViewTransformer(new DateTimeToArrayTransformer($options['data_timezone'], $options['user_timezone'], array('year', 'month', 'day'))); } if ('string' === $options['input']) { $builder->addModelTransformer(new ReversedTransformer(new DateTimeToStringTransformer($options['data_timezone'], $options['data_timezone'], 'Y-m-d'))); } elseif ('timestamp' === $options['input']) { $builder->addModelTransformer(new ReversedTransformer(new DateTimeToTimestampTransformer($options['data_timezone'], $options['data_timezone']))); } elseif ('array' === $options['input']) { $builder->addModelTransformer(new ReversedTransformer(new DateTimeToArrayTransformer($options['data_timezone'], $options['data_timezone'], array('year', 'month', 'day')))); } $builder->setAttribute('formatter', $formatter); }
/** * {@inheritdoc} */ public function buildForm(FormBuilderInterface $builder, array $options) { $parts = array('hour', 'minute'); $format = 'H:i'; if ($options['with_seconds']) { $format = 'H:i:s'; $parts[] = 'second'; } if ('single_text' === $options['widget']) { $builder->addViewTransformer(new DateTimeToStringTransformer($options['model_timezone'], $options['view_timezone'], $format)); } else { $hourOptions = $minuteOptions = $secondOptions = array('error_bubbling' => true); if ('choice' === $options['widget']) { $hours = $minutes = array(); foreach ($options['hours'] as $hour) { $hours[$hour] = str_pad($hour, 2, '0', STR_PAD_LEFT); } foreach ($options['minutes'] as $minute) { $minutes[$minute] = str_pad($minute, 2, '0', STR_PAD_LEFT); } // Only pass a subset of the options to children $hourOptions['choices'] = $hours; $hourOptions['empty_value'] = $options['empty_value']['hour']; $minuteOptions['choices'] = $minutes; $minuteOptions['empty_value'] = $options['empty_value']['minute']; if ($options['with_seconds']) { $seconds = array(); foreach ($options['seconds'] as $second) { $seconds[$second] = str_pad($second, 2, '0', STR_PAD_LEFT); } $secondOptions['choices'] = $seconds; $secondOptions['empty_value'] = $options['empty_value']['second']; } // Append generic carry-along options foreach (array('required', 'translation_domain') as $passOpt) { $hourOptions[$passOpt] = $minuteOptions[$passOpt] = $options[$passOpt]; if ($options['with_seconds']) { $secondOptions[$passOpt] = $options[$passOpt]; } } } $builder->add('hour', $options['widget'], $hourOptions)->add('minute', $options['widget'], $minuteOptions); if ($options['with_seconds']) { $builder->add('second', $options['widget'], $secondOptions); } $builder->addViewTransformer(new DateTimeToArrayTransformer($options['model_timezone'], $options['view_timezone'], $parts, 'text' === $options['widget'])); } if ('string' === $options['input']) { $builder->addModelTransformer(new ReversedTransformer(new DateTimeToStringTransformer($options['model_timezone'], $options['model_timezone'], 'H:i:s'))); } elseif ('timestamp' === $options['input']) { $builder->addModelTransformer(new ReversedTransformer(new DateTimeToTimestampTransformer($options['model_timezone'], $options['model_timezone']))); } elseif ('array' === $options['input']) { $builder->addModelTransformer(new ReversedTransformer(new DateTimeToArrayTransformer($options['model_timezone'], $options['model_timezone'], $parts))); } }
/** * (non-PHPdoc) * @see Symfony\Component\Form.AbstractType::buildForm() */ public function buildForm(FormBuilderInterface $builder, array $options) { $builder->addViewTransformer(new DateTimeToStringTransformer($options['date_timezone'], $options['user_timezone'], $options['datetime_format'])); if ('string' === $options['input']) { $builder->addModelTransformer(new ReversedTransformer(new DateTimeToStringTransformer($options['date_timezone'], $options['date_timezone'], $options['datetime_format']))); } elseif ('timestamp' === $options['input']) { $builder->addModelTransformer(new ReversedTransformer(new DateTimeToTimestampTransformer($options['date_timezone'], $options['date_timezone']))); } elseif ('array' === $options['input']) { $builder->addModelTransformer(new ReversedTransformer(new DateTimeToArrayTransformer($options['date_timezone'], $options['date_timezone'], $options['parts']))); } }
/** * {@inheritdoc} */ public function buildForm(FormBuilderInterface $builder, array $options) { $dateFormat = is_int($options['format']) ? $options['format'] : self::DEFAULT_FORMAT; $timeFormat = \IntlDateFormatter::NONE; $calendar = \IntlDateFormatter::GREGORIAN; $pattern = is_string($options['format']) ? $options['format'] : null; if (!in_array($dateFormat, self::$acceptedFormats, true)) { throw new InvalidOptionsException('The "format" option must be one of the IntlDateFormatter constants (FULL, LONG, MEDIUM, SHORT) or a string representing a custom format.'); } if (null !== $pattern && (false === strpos($pattern, 'y') || false === strpos($pattern, 'M') || false === strpos($pattern, 'd'))) { throw new InvalidOptionsException(sprintf('The "format" option should contain the letters "y", "M" and "d". Its current value is "%s".', $pattern)); } if ('single_text' === $options['widget']) { $builder->addViewTransformer(new DateTimeToLocalizedStringTransformer($options['model_timezone'], $options['view_timezone'], $dateFormat, $timeFormat, $calendar, $pattern)); } else { $yearOptions = $monthOptions = $dayOptions = array('error_bubbling' => true); $formatter = new \IntlDateFormatter(\Locale::getDefault(), $dateFormat, $timeFormat, null, $calendar, $pattern); // new \intlDateFormatter may return null instead of false in case of failure, see https://bugs.php.net/bug.php?id=66323 if (!$formatter) { throw new InvalidOptionsException(intl_get_error_message(), intl_get_error_code()); } $formatter->setLenient(false); if ('choice' === $options['widget']) { // Only pass a subset of the options to children $yearOptions['choices'] = $this->formatTimestamps($formatter, '/y+/', $this->listYears($options['years'])); $yearOptions['choices_as_values'] = true; $yearOptions['placeholder'] = $options['placeholder']['year']; $yearOptions['choice_translation_domain'] = $options['choice_translation_domain']['year']; $monthOptions['choices'] = $this->formatTimestamps($formatter, '/[M|L]+/', $this->listMonths($options['months'])); $monthOptions['choices_as_values'] = true; $monthOptions['placeholder'] = $options['placeholder']['month']; $monthOptions['choice_translation_domain'] = $options['choice_translation_domain']['month']; $dayOptions['choices'] = $this->formatTimestamps($formatter, '/d+/', $this->listDays($options['days'])); $dayOptions['choices_as_values'] = true; $dayOptions['placeholder'] = $options['placeholder']['day']; $dayOptions['choice_translation_domain'] = $options['choice_translation_domain']['day']; } // Append generic carry-along options foreach (array('required', 'translation_domain') as $passOpt) { $yearOptions[$passOpt] = $monthOptions[$passOpt] = $dayOptions[$passOpt] = $options[$passOpt]; } $builder->add('year', self::$widgets[$options['widget']], $yearOptions)->add('month', self::$widgets[$options['widget']], $monthOptions)->add('day', self::$widgets[$options['widget']], $dayOptions)->addViewTransformer(new DateTimeToArrayTransformer($options['model_timezone'], $options['view_timezone'], array('year', 'month', 'day')))->setAttribute('formatter', $formatter); } if ('string' === $options['input']) { $builder->addModelTransformer(new ReversedTransformer(new DateTimeToStringTransformer($options['model_timezone'], $options['model_timezone'], 'Y-m-d'))); } elseif ('timestamp' === $options['input']) { $builder->addModelTransformer(new ReversedTransformer(new DateTimeToTimestampTransformer($options['model_timezone'], $options['model_timezone']))); } elseif ('array' === $options['input']) { $builder->addModelTransformer(new ReversedTransformer(new DateTimeToArrayTransformer($options['model_timezone'], $options['model_timezone'], array('year', 'month', 'day')))); } }
public function buildForm(FormBuilderInterface $builder, array $options) { $entityManager = $options['em']; $dataClass = $options['tag_class']; $transformer = new TagTransformer($entityManager, $dataClass); $builder->addModelTransformer($transformer); }
/** * {@inheritdoc} */ public function buildForm(FormBuilderInterface $builder, array $options) { foreach ($options['variable']->getOptions() as $i => $option) { $builder->add(Urlizer::urlize($option->getName()), sprintf('sylius_%s_option_value_choice', $this->variableName), ['label' => $option->getPresentation(), 'option' => $option, 'property_path' => '[' . $i . ']']); } $builder->addModelTransformer(new VariantToCombinationTransformer($options['variable'])); }
/** * Builds the form. * * This method is called after the extended type has built the form to * further modify it. * * @see FormTypeInterface::buildForm() * * @param FormBuilderInterface $builder The form builder * @param array $options The options */ public function buildForm(FormBuilderInterface $builder, array $options) { if ($options['encryption_profile'] === false) { return; } $builder->addModelTransformer(new EncryptTransformer($this->cipherTextGenerator, $options['encryption_profile'])); }
/** * @param FormBuilderInterface $builder * @param array $options options */ public function buildForm(FormBuilderInterface $builder, array $options) { $builder->add('site', TextType::class, ['constraints' => new Url()]); $builder->add('compare_sites', TextareaType::class, ['constraints' => new MultiUrl()]); $builder->add('save', SubmitType::class); $builder->addModelTransformer($this->transformer); }
public function buildForm(FormBuilderInterface $builder, array $options) { $transformer = new ProductToNumberTransformer($this->manager); $builder->addModelTransformer($transformer); //$builder // ->add('product', 'EntityType::class', ['class'=>'AppBundle:product', 'property'=>'name']); }
/** * {@inheritDoc} */ public function buildForm(FormBuilderInterface $builder, array $options) { $transformer = new ArrayKeyTransformer('content_id'); $contentTransformer = new IdToEntityTransformer($this->contentManager); $builder->add($builder->create('content_id', 'hidden')->addModelTransformer($contentTransformer)); $builder->addModelTransformer($transformer); }
/** * @param FormBuilderInterface $builder * @param array $options */ public function buildForm(FormBuilderInterface $builder, array $options) { $defaultProvider = $this->mediaManager->getDefaultProviderInstance(); $builder->add('title', 'textarea')->add('category', 'mediatreebrowser', array('class' => $defaultProvider->getCategoryEntityClass(), 'property' => 'name', 'constraints' => array(new NotNull(), new NotBlank())))->add('credits')->add('alt')->add('src', 'hidden')->add('hash', 'hidden')->add('name', 'hidden')->add('nameOriginal', 'hidden')->add('path', 'hidden'); $transformer = new MediaTransformer($this->mediaManager); $builder->addModelTransformer($transformer); }
public function buildForm(FormBuilderInterface $builder, array $options) { if ($options['add_transformer']) { $transformer = new TagEntityModelTransformer($this->factory->getEntityManager(), 'MauticLeadBundle:Tag', 'id', $options['multiple'], true); $builder->addModelTransformer($transformer); } }
/** * {@inheritdoc} */ public function buildForm(FormBuilderInterface $builder, array $options) { $builder->add('tbbc_amount', 'Symfony\\Component\\Form\\Extension\\Core\\Type\\TextType'); $transformer = new SimpleMoneyToArrayTransformer($this->decimals); $transformer->setCurrency($options['currency']); $builder->addModelTransformer($transformer); }
/** * (non-PHPdoc) * @see Symfony\Component\Form.AbstractType::buildForm() */ public function buildForm(FormBuilderInterface $builder, array $options) { if (null !== $options['class']) { $this->transformer->setClass($options['class']); $builder->addModelTransformer($this->transformer); } }
/** * {@inheritdoc} */ public function buildForm(FormBuilderInterface $builder, array $options) { $builder->addModelTransformer(new TaggingTransformer($this->tagRepository, $options['delimiter'])); $builder->addEventListener(FormEvents::PRE_SUBMIT, function (FormEvent $event) use($options) { $tags = $event->getData(); $event->setData(is_array($tags) ? implode($options['delimiter'], $tags) : $tags); }); // TODO: BUG FIXME not work when object have no id (none persited object) $builder->addEventListener(FormEvents::POST_SUBMIT, function (FormEvent $event) { $object = $event->getForm()->getParent()->getData(); if (!$object instanceof TagsAwareInterface || !$object instanceof OriginContextInterface) { return; } $tags = $this->tagRepository->resolveWithString($event->getData()) ?: array(); $object->setTags(null); /** @var TaggingInterface[] $oldTaggings */ $oldTaggings = $this->taggingRepository->findBy(array('originAlias' => $object->getOriginalAlias(), 'originId' => $object->getId())); foreach ($oldTaggings as $oldTagging) { if (!in_array($oldTagging->getTag(), $tags)) { $this->taggingRepository->getManager()->remove($oldTagging); } } $this->taggingRepository->getManager()->flush(); foreach ($tags as $tag) { $tagging = $this->taggingRepository->findWithTagAndAlias($tag, $object, true); $this->originator->setOrigin($tagging, $object); $this->taggingRepository->add($tagging); $object->addTag($tag); } }); }
public function buildForm(FormBuilderInterface $builder, array $options) { $builder->addModelTransformer(new CallbackTransformer(function ($currencyAsInt) { //int -> text $string = (string) $currencyAsInt; $string = str_pad($string, 3, '0', STR_PAD_LEFT); $length = strlen($string); $right = substr($string, $length - 2, 2); $left = substr($string, 0, $length - 2); $value = $left . ',' . $right; return $value; }, function ($currencyAsString) { //text -> int $string = $currencyAsString; $string = str_replace('.', '', $string); $parts = explode(',', $string); $right = 0; if (count($parts) > 1) { $right = array_pop($parts); $right = substr($right, 0, 2); $right = str_pad($right, 2, '0'); $right = intval($right); } $left = implode($parts); $left = intval($left); $value = $right; if ($left > 0) { $value = $left * 100 + $value; } return $value; })); }
/** * @param FormBuilderInterface $builder * @param array $options * * @throws AlreadySubmittedException * @throws LogicException * @throws UnexpectedTypeException * @throws \InvalidArgumentException */ public function buildForm(FormBuilderInterface $builder, array $options) { $builder->add('family', FamilySelectorType::class, ['label' => false, 'families' => $options['families'], 'empty_value' => 'sidus.family.selector.empty_value']); $builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) use($options) { $form = $event->getForm(); /** @var DataInterface $data */ $data = $event->getData(); /** @var FamilyInterface[] $families */ $families = $options['families']; foreach ($families as $family) { $selected = false; if ($data instanceof DataInterface) { $selected = $family->getCode() === $data->getFamilyCode(); } $form->add('data_' . $family->getCode(), AutocompleteDataSelectorType::class, ['label' => false, 'family' => $family, 'auto_init' => $selected, 'attr' => ['data-family' => $family->getCode()]]); } }); $builder->addModelTransformer(new CallbackTransformer(function ($originalData) { if ($originalData instanceof DataInterface) { return ['family' => $originalData->getFamily(), 'data_' . $originalData->getFamilyCode() => $originalData]; } return $originalData; }, function ($submittedData) { $family = $submittedData['family']; if ($family instanceof FamilyInterface) { return $submittedData['data_' . $family->getCode()]; } return null; })); }
/** * {@inheritdoc} */ public function buildForm(FormBuilderInterface $builder, array $options) { $builder->addViewTransformer(new ArrayToStringTransformer($options['separator'], array('from', 'to'))); if ($options['use_daterange_entity']) { $builder->addModelTransformer(new DateRangeToArrayTransformer($options['format'])); } }
public function buildForm(FormBuilderInterface $builder, array $options) { $builder->addModelTransformer(new ContactNumberWithWidgetDataTransformer()); $builder->add('country_code'); $builder->add('abbr'); $builder->add('number'); }
public function buildForm(FormBuilderInterface $builder, array $options) { foreach ($this->fields as $field) { list($name, $type, $options) = $field; $builder->add($name, $type, $options); } $class = $this->class; foreach ($this->eventListeners as $eventListener) { list($method, $event, $priority) = $eventListener; $builder->addEventListener($event, function (FormEvent $event) use($builder, $class, $method) { $data = $builder->getData(); if (!$data instanceof $class) { $data = $event->getData(); if (!$data instanceof $class) { return; } } if (!method_exists($data, $method)) { return; } $data->{$method}($event); }, $priority); } foreach ($this->eventSubscribers as $eventSubscriber) { $builder->addEventSubscriber($eventSubscriber); } foreach ($this->modelTransformers as $modelTransformer) { $builder->addModelTransformer($modelTransformer); } foreach ($this->viewTransformers as $viewTransformer) { $builder->addViewTransformer($viewTransformer); } }
/** * {@inheritdoc} */ public function buildForm(FormBuilderInterface $builder, array $options) { $builder->addModelTransformer($this->denormalizedEntityTransformer); $this->tagManager->setLocale($options['locale']); // On Pre-Submit, create the news posted Tags otherwise the form won't be valid $builder->addEventListener(FormEvents::PRE_SUBMIT, function ($event) use($options) { // Data when posted $tags = $event->getData(); $entity = $event->getForm()->getParent()->getData(); // Loop through the posted tags (if not numeric, it's a news Tag) if (is_array($tags)) { foreach ($tags as $key => $tagId) { if (!is_numeric($tagId)) { $tag = $this->tagManager->loadOrCreateTag($tagId, $options['use_global_tags'] ? null : $entity->getResourceType()); $tags[$key] = $tag->getId(); $entity->setTagsUpdatedAt(new \DateTime()); } } // Update the posted data with the newly created tags $event->setData($tags); $this->taggableListener->setNeedToFlush(true); } elseif (null === $tags && count($entity->getTags())) { // All tags are removed $this->taggableListener->setNeedToFlush(true); } }, 900); }
/** * {@inheritdoc} */ public function buildForm(FormBuilderInterface $builder, array $options) { $builder->addEventListener(FormEvents::PRE_SUBMIT, function (FormEvent $event) { $products = $event->getData(); if (!$products) { return; } $form = $event->getForm(); foreach ($products as $key => $product) { if ($product[ProductDataStorage::PRODUCT_SKU_KEY] === '' && $product[ProductDataStorage::PRODUCT_QUANTITY_KEY] === '') { // disable row validation $rowFormConfig = $form->get($key)->getConfig(); $formType = $rowFormConfig->getType()->getName(); $formOptions = $rowFormConfig->getOptions(); $formOptions['validation_groups'] = false; $form->remove($key); $form->add($key, $formType, $formOptions); } elseif ($product[ProductDataStorage::PRODUCT_QUANTITY_KEY] === '') { // default quantity $products[$key][ProductDataStorage::PRODUCT_QUANTITY_KEY] = '1'; } } $event->setData($products); }); // remove empty rows from data $builder->addModelTransformer(new ProductCollectionTransformer()); }
public function buildForm(FormBuilderInterface $builder, array $options) { $allowAllMethods = !count($options['allowed_methods']); $options['available_methods'] = array(); foreach ($this->paymentMethods as $method) { if (!$allowAllMethods && !in_array($method, $options['allowed_methods'], true)) { continue; } $options['available_methods'][] = $method; } if (!$options['available_methods']) { throw new \RuntimeException(sprintf('You have not selected any payment methods. Available methods: "%s"', implode(', ', $this->paymentMethods))); } $builder->add('method', 'choice', array('choices' => $this->buildChoices($options['available_methods']), 'expanded' => true, 'data' => $options['default_method'])); foreach ($options['available_methods'] as $method) { $methodOptions = isset($options['method_options'][$method]) ? $options['method_options'] : array(); $builder->add('data_' . $method, $method, $methodOptions); } $self = $this; $builder->addEventListener(FormEvents::POST_BIND, function ($form) use($self, $options) { $self->validate($form, $options); }); $builder->addModelTransformer(new CallbackTransformer(function ($data) use($self, $options) { return $self->transform($data, $options); }, function ($data) use($self, $options) { return $self->reverseTransform($data, $options); }), true); }
/** * {@inheritdoc} */ public function buildForm(FormBuilderInterface $builder, array $options) { $repository = $this->manager->getRepository($options['class']); $transformer = new EntityToIdentifierTransformer($repository, $options['identifier']); $builder->addModelTransformer($transformer); $builder->setAttribute('repository', $repository); }
/** * {@inheritdoc} */ public function buildForm(FormBuilderInterface $builder, array $options) { $builder->add('file', $this->getFieldType('file'), array('required' => $options['required'], 'label' => $options['label'], 'attr' => $options['attr'])); $builder->addModelTransformer(new FileTransformer()); if ($options['allow_delete']) { $this->buildDeleteField($builder, $options); } }