本文整理汇总了PHP中Symfony\Component\Form\FormBuilderInterface::addViewTransformer方法的典型用法代码示例。如果您正苦于以下问题:PHP FormBuilderInterface::addViewTransformer方法的具体用法?PHP FormBuilderInterface::addViewTransformer怎么用?PHP FormBuilderInterface::addViewTransformer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Form\FormBuilderInterface
的用法示例。
在下文中一共展示了FormBuilderInterface::addViewTransformer方法的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
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->addViewTransformer($this->createEntitiesToIdsTransformer($options));
if ($options['multiple']) {
$builder->addViewTransformer(new ArrayToStringTransformer($options['values_delimiter'], true))->addEventSubscriber(new FixArrayToStringListener($options['values_delimiter']));
}
}
示例3: buildForm
public function buildForm(FormBuilderInterface $builder, array $options)
{
if (isset($options['transformer'])) {
$builder->addViewTransformer(new $options['transformer']());
} else {
$builder->addViewTransformer(new IdentifiableToUriTransformer($options['class'], $options['dsl_client']));
}
}
示例4: buildForm
public function buildForm(FormBuilderInterface $builder, array $options)
{
// @todo I could combine the transformers below into a single class...
if ($options['multiple']) {
$builder->addViewTransformer(new EntitiesToPropertyTransformer($options['em'] ?: $this->em, $options['class'], $options['property']), true);
} else {
$builder->addViewTransformer(new EntityToPropertyTransformer($options['em'] ?: $this->em, $options['class'], $options['property']), true);
}
}
示例5: buildForm
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
if ($options['choice_data'] == 'scalar') {
if ($options['multiple']) {
$builder->addViewTransformer(new ValuesToChoicesTransformer($options['choice_list']), true);
} else {
$builder->addViewTransformer(new ValueToChoiceTransformer($options['choice_list']), true);
}
}
}
示例6: buildForm
/**
* @param FormBuilderInterface $builder
* @param array $options
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->resetViewTransformers();
$builder->addViewTransformer(new ObjectToIdTransformer($this->em, $options['class']));
if ($options['multiple']) {
$builder->addViewTransformer(new EntityArrayToIdArrayTransformer($this->em, null));
} else {
$builder->addViewTransformer(new ArrayToIdTransformer($this->em, null));
}
}
示例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
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$parts = array('year', 'month', 'day', 'hour');
$dateParts = array('year', 'month', 'day');
$timeParts = array('hour');
if ($options['with_minutes']) {
$parts[] = 'minute';
$timeParts[] = 'minute';
}
if ($options['with_seconds']) {
$parts[] = 'second';
$timeParts[] = 'second';
}
$dateFormat = is_int($options['date_format']) ? $options['date_format'] : self::DEFAULT_DATE_FORMAT;
$timeFormat = self::DEFAULT_TIME_FORMAT;
$calendar = \IntlDateFormatter::GREGORIAN;
$pattern = is_string($options['format']) ? $options['format'] : null;
if (!in_array($dateFormat, self::$acceptedFormats, true)) {
throw new InvalidOptionsException('The "date_format" option must be one of the IntlDateFormatter constants (FULL, LONG, MEDIUM, SHORT) or a string representing a custom format.');
}
if ('single_text' === $options['widget']) {
if (self::HTML5_FORMAT === $pattern) {
$builder->addViewTransformer(new DateTimeToRfc3339Transformer($options['model_timezone'], $options['view_timezone']));
} else {
$builder->addViewTransformer(new DateTimeToLocalizedStringTransformer($options['model_timezone'], $options['view_timezone'], $dateFormat, $timeFormat, $calendar, $pattern));
}
} else {
// Only pass a subset of the options to children
$dateOptions = array_intersect_key($options, array_flip(array('years', 'months', 'days', 'empty_value', 'placeholder', 'required', 'translation_domain', 'html5', 'invalid_message', 'invalid_message_parameters')));
$timeOptions = array_intersect_key($options, array_flip(array('hours', 'minutes', 'seconds', 'with_minutes', 'with_seconds', 'empty_value', 'placeholder', 'required', 'translation_domain', 'html5', 'invalid_message', 'invalid_message_parameters')));
if (null !== $options['date_widget']) {
$dateOptions['widget'] = $options['date_widget'];
}
if (null !== $options['time_widget']) {
$timeOptions['widget'] = $options['time_widget'];
}
if (null !== $options['date_format']) {
$dateOptions['format'] = $options['date_format'];
}
$dateOptions['input'] = $timeOptions['input'] = 'array';
$dateOptions['error_bubbling'] = $timeOptions['error_bubbling'] = true;
$builder->addViewTransformer(new DataTransformerChain(array(new DateTimeToArrayTransformer($options['model_timezone'], $options['view_timezone'], $parts), new ArrayToPartsTransformer(array('date' => $dateParts, 'time' => $timeParts)))))->add('date', 'date', $dateOptions)->add('time', 'time', $timeOptions);
}
if ('string' === $options['input']) {
$builder->addModelTransformer(new ReversedTransformer(new DateTimeToStringTransformer($options['model_timezone'], $options['model_timezone'])));
} 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)));
}
}
示例9: buildForm
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
if ($options['multiple']) {
if (array_key_exists('choice_loader', $options) && $options['choice_loader'] !== null) {
// SF2.7+
$builder->addViewTransformer(new ModelsToArrayTransformer($options['choice_loader'], $options['model_manager'], $options['class']), true);
} else {
$builder->addViewTransformer(new LegacyModelsToArrayTransformer($options['choice_list']), true);
}
$builder->addEventSubscriber(new MergeCollectionListener($options['model_manager']));
} else {
$builder->addViewTransformer(new ModelToIdTransformer($options['model_manager'], $options['class']), true);
}
}
示例10: buildForm
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
// Overwrite required option for child fields
$options['first_options']['required'] = $options['required'];
$options['second_options']['required'] = $options['required'];
$builder->addViewTransformer(new ValueToDuplicatesTransformer(array($options['first_name'], $options['second_name'])))->add($options['first_name'], $options['type'], array_merge($options['options'], $options['first_options']))->add($options['second_name'], $options['type'], array_merge($options['options'], $options['second_options']));
}
示例11: buildForm
/**
* @inheritdoc
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->addEventSubscriber($this->subscriber);
$builder->addViewTransformer(new ResourceTransformer());
$builder->add('file', 'file');
$builder->add('delete', 'checkbox', ['required' => false]);
}
示例12:
function it_builds_form(FormBuilderInterface $builder, IdentifiableObjectRepositoryInterface $repository, DataTransformerInterface $transformer, $transformerFactory)
{
$options = ['repository' => $repository->getWrappedObject(), 'multiple' => false];
$transformerFactory->create($repository, ['multiple' => false])->willReturn($transformer);
$builder->addViewTransformer($transformer, true)->shouldBeCalled();
$this->buildForm($builder, $options);
}
示例13: buildForm
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);
}
}
示例14: buildForm
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('years', 'choice', array('choices' => range(0, $options['nb_years_choices'], 1)))->add('months', 'choice', array('choices' => range(0, 11, 1)))->add('days', 'choice', array('choices' => range(0, 30, 1)));
if ($options['with_hours']) {
$builder->add('hours', 'choice', array('choices' => range(0, 23, 1)));
}
if ($options['with_minutes']) {
$builder->add('minutes', 'choice', array('choices' => range(0, 59, 1)));
}
if ($options['with_seconds']) {
$builder->add('seconds', 'choice', array('choices' => range(0, 59, 1)));
}
//Transform to \DateInterval & reverse
$builder->addViewTransformer(new CallbackTransformer(function (\DateInterval $value = null) {
if ($value === null) {
return null;
}
return array('seconds' => $value->s, 'minutes' => $value->i, 'hours' => $value->h, 'days' => $value->d, 'months' => $value->m, 'years' => $value->y);
}, function ($value) {
if ($value === null) {
return null;
}
$interval = new \DateInterval('PT0S');
$interval->s = isset($value['seconds']) ? $value['seconds'] : 0;
$interval->i = isset($value['minutes']) ? $value['minutes'] : 0;
$interval->h = isset($value['hours']) ? $value['hours'] : 0;
$interval->d = isset($value['days']) ? $value['days'] : 0;
$interval->m = isset($value['months']) ? $value['months'] : 0;
$interval->y = isset($value['years']) ? $value['years'] : 0;
//If no interval, return null
$now = new \DateTime();
$copy = clone $now;
return $now->getTimestamp() === $copy->add($interval)->getTimestamp() ? null : $interval;
}));
}
示例15: buildForm
public function buildForm(FormBuilderInterface $builder, array $options)
{
if (null === $options['class']) {
throw new InvalidConfigurationException('Option "class" is empty');
}
if (null === $options['parent_field']) {
throw new InvalidConfigurationException('Option "parent_field" is empty');
}
if (null === $options['property']) {
throw new InvalidConfigurationException('Option "property" is empty');
}
$builder->addViewTransformer(new EntityToIdTransformer($this->em, $options['class']), true);
$query = $options['query'];
if ($query instanceof \Closure) {
$queryBuilder = $query($this->em->getRepository($options['class']));
$query = $queryBuilder->getQuery()->getDql();
}
$builder->setAttribute('class', $options['class']);
$builder->setAttribute("parent_field", $options['parent_field']);
$builder->setAttribute("no_result_msg", $options['no_result_msg']);
$builder->setAttribute("empty_value", $options['empty_value']);
$builder->setAttribute("property", $options['property']);
$builder->setAttribute("em_name", $options['em_name']);
$builder->setAttribute('query', $query);
$builder->setAttribute("order_direction", $options['order_direction']);
$builder->setAttribute("order_property", $options['order_property']);
}