本文整理汇总了PHP中Symfony\Component\Form\FormBuilderInterface::addModelTransformer方法的典型用法代码示例。如果您正苦于以下问题:PHP FormBuilderInterface::addModelTransformer方法的具体用法?PHP FormBuilderInterface::addModelTransformer怎么用?PHP FormBuilderInterface::addModelTransformer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Form\FormBuilderInterface
的用法示例。
在下文中一共展示了FormBuilderInterface::addModelTransformer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: buildForm
public function buildForm(FormBuilderInterface $builder, array $options)
{
$transformer = new ManyRelatedTransformer($this->doctrineRegistry, $options['entityName']);
$viewTransformer = new ArrayToStringTransformer();
$builder->addModelTransformer($transformer);
$builder->addViewTransformer($viewTransformer);
}
示例2: buildForm
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());
}
示例3: buildForm
/**
* @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);
}
}
示例4: buildForm
/**
* {@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(','));
}
}
示例5: buildForm
/**
* {@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));
}
}
示例6: buildForm
/**
* {@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);
}
示例7: buildForm
/**
* {@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)));
}
}
示例8: buildForm
/**
* (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'])));
}
}
示例9: buildForm
/**
* {@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'))));
}
}
示例10: buildForm
public function buildForm(FormBuilderInterface $builder, array $options)
{
$entityManager = $options['em'];
$dataClass = $options['tag_class'];
$transformer = new TagTransformer($entityManager, $dataClass);
$builder->addModelTransformer($transformer);
}
示例11: buildForm
/**
* {@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']));
}
示例12: buildForm
/**
* 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']));
}
示例13: buildForm
/**
* @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);
}
示例14: buildForm
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']);
}
示例15: buildForm
/**
* {@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);
}