Skip to content

Commit

Permalink
[Form] Renamed client and application format to view and model format
Browse files Browse the repository at this point in the history
  • Loading branch information
webmozart committed May 25, 2012
1 parent 8cae328 commit bec8015
Show file tree
Hide file tree
Showing 25 changed files with 316 additions and 178 deletions.
29 changes: 28 additions & 1 deletion UPGRADE-2.1.md
Expand Up @@ -467,8 +467,10 @@
* `getClientTransformers`
* `getAttribute`
* `hasAttribute`
* `getClientData`

You can access these methods on the `FormConfigInterface` object instead.
The method `getClientData` has a new equivalent that is named `getViewData`.
You can access all other methods on the `FormConfigInterface` object instead.

Before:

Expand Down Expand Up @@ -643,6 +645,31 @@
public function buildView(FormViewInterface $view, FormInterface $form, array $options)
public function buildViewBottomUp(FormViewInterface $view, FormInterface $form, array $options)
```

* The following methods in `FormBuilder` were deprecated and have a new equivalent:

* `prependClientTransformer`: `addViewTransformer`
* `appendClientTransformer`: no new equivalent, should not be used
* `getClientTransformers`: `getViewTransformers`
* `resetClientTransformers`: `resetViewTransformers`
* `prependNormTransformer`: no new equivalent, should not be used
* `appendNormTransformer`: `addModelTransformer`
* `getNormTransformers`: `getModelTransformers`
* `resetNormTransformers`: `resetModelTransformers`

The deprecated methods will be removed in Symfony 2.3. You are advised to update your application.

Before:

```
$builder->prependClientTransformer(new MyTransformer());
```

After:

```
$builder->addViewTransformer(new MyTransformer());
```

### Validator

Expand Down
18 changes: 18 additions & 0 deletions src/Symfony/Component/Form/CHANGELOG.md
Expand Up @@ -75,13 +75,31 @@ CHANGELOG
* errors are not mapped to unsynchronized forms anymore
* [BC BREAK] changed Form constructor to accept a single `FormConfigInterface` object
* [BC BREAK] changed argument order in the FormBuilder constructor
* added Form method `getViewData`
* deprecated Form methods
* `getTypes`
* `getErrorBubbling`
* `getNormTransformers`
* `getClientTransformers`
* `getAttribute`
* `hasAttribute`
* `getClientData`
* added FormBuilder methods
* `addViewTransformer`
* `getViewTransformers`
* `resetViewTransformers`
* `addModelTransformer`
* `getModelTransformers`
* `resetModelTransformers`
* deprecated FormBuilder methods
* `prependClientTransformer`
* `appendClientTransformer`
* `getClientTransformers`
* `resetClientTransformers`
* `prependNormTransformer`
* `appendNormTransformer`
* `getNormTransformers`
* `resetNormTransformers`
* deprecated the option "validation_constraint" in favor of the new
option "constraints"
* removed superfluous methods from DataMapperInterface
Expand Down
Expand Up @@ -26,7 +26,7 @@ class CheckboxType extends AbstractType
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->appendClientTransformer(new BooleanToStringTransformer($options['value']))
->addViewTransformer(new BooleanToStringTransformer($options['value']))
;
}

Expand All @@ -37,7 +37,7 @@ public function buildView(FormViewInterface $view, FormInterface $form, array $o
{
$view
->set('value', $options['value'])
->set('checked', null !== $form->getClientData())
->set('checked', null !== $form->getViewData())
;
}

Expand Down
8 changes: 4 additions & 4 deletions src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php
Expand Up @@ -46,20 +46,20 @@ public function buildForm(FormBuilderInterface $builder, array $options)

if ($options['multiple']) {
$builder
->appendClientTransformer(new ChoicesToBooleanArrayTransformer($options['choice_list']))
->addViewTransformer(new ChoicesToBooleanArrayTransformer($options['choice_list']))
->addEventSubscriber(new FixCheckboxInputListener($options['choice_list']), 10)
;
} else {
$builder
->appendClientTransformer(new ChoiceToBooleanArrayTransformer($options['choice_list']))
->addViewTransformer(new ChoiceToBooleanArrayTransformer($options['choice_list']))
->addEventSubscriber(new FixRadioInputListener($options['choice_list']), 10)
;
}
} else {
if ($options['multiple']) {
$builder->appendClientTransformer(new ChoicesToValuesTransformer($options['choice_list']));
$builder->addViewTransformer(new ChoicesToValuesTransformer($options['choice_list']));
} else {
$builder->appendClientTransformer(new ChoiceToValueTransformer($options['choice_list']));
$builder->addViewTransformer(new ChoiceToValueTransformer($options['choice_list']));
}
}

Expand Down
Expand Up @@ -43,7 +43,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
}

if ('single_text' === $options['widget']) {
$builder->appendClientTransformer(new DateTimeToStringTransformer($options['data_timezone'], $options['user_timezone'], $format));
$builder->addViewTransformer(new DateTimeToStringTransformer($options['data_timezone'], $options['user_timezone'], $format));
} else {
// Only pass a subset of the options to children
$dateOptions = array_intersect_key($options, array_flip(array(
Expand Down Expand Up @@ -86,7 +86,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
$timeOptions['input'] = 'array';

$builder
->appendClientTransformer(new DataTransformerChain(array(
->addViewTransformer(new DataTransformerChain(array(
new DateTimeToArrayTransformer($options['data_timezone'], $options['user_timezone'], $parts),
new ArrayToPartsTransformer(array(
'date' => array('year', 'month', 'day'),
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Form/Extension/Core/Type/DateType.php
Expand Up @@ -63,7 +63,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
);

if ('single_text' === $options['widget']) {
$builder->appendClientTransformer(new DateTimeToLocalizedStringTransformer($options['data_timezone'], $options['user_timezone'], $format, \IntlDateFormatter::NONE, \IntlDateFormatter::GREGORIAN, $pattern));
$builder->addViewTransformer(new DateTimeToLocalizedStringTransformer($options['data_timezone'], $options['user_timezone'], $format, \IntlDateFormatter::NONE, \IntlDateFormatter::GREGORIAN, $pattern));
} else {
$yearOptions = $monthOptions = $dayOptions = array();

Expand Down Expand Up @@ -110,7 +110,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
->add('year', $options['widget'], $yearOptions)
->add('month', $options['widget'], $monthOptions)
->add('day', $options['widget'], $dayOptions)
->appendClientTransformer(new DateTimeToArrayTransformer(
->addViewTransformer(new DateTimeToArrayTransformer(
$options['data_timezone'], $options['user_timezone'], array('year', 'month', 'day')
))
;
Expand Down
Expand Up @@ -97,7 +97,7 @@ public function buildView(FormViewInterface $view, FormInterface $form, array $o
->set('read_only', $readOnly)
->set('errors', $form->getErrors())
->set('valid', $form->isBound() ? $form->isValid() : true)
->set('value', $form->getClientData())
->set('value', $form->getViewData())
->set('disabled', $form->isDisabled())
->set('required', $form->isRequired())
->set('max_length', $options['max_length'])
Expand Down
Expand Up @@ -23,7 +23,7 @@ class IntegerType extends AbstractType
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->appendClientTransformer(
$builder->addViewTransformer(
new IntegerToLocalizedStringTransformer(
$options['precision'],
$options['grouping'],
Expand Down
Expand Up @@ -28,7 +28,7 @@ class MoneyType extends AbstractType
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->appendClientTransformer(new MoneyToLocalizedStringTransformer(
->addViewTransformer(new MoneyToLocalizedStringTransformer(
$options['precision'],
$options['grouping'],
null,
Expand Down
Expand Up @@ -23,7 +23,7 @@ class NumberType extends AbstractType
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->appendClientTransformer(new NumberToLocalizedStringTransformer(
$builder->addViewTransformer(new NumberToLocalizedStringTransformer(
$options['precision'],
$options['grouping'],
$options['rounding_mode']
Expand Down
Expand Up @@ -23,7 +23,7 @@ class PercentType extends AbstractType
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->appendClientTransformer(new PercentToLocalizedStringTransformer($options['precision'], $options['type']));
$builder->addViewTransformer(new PercentToLocalizedStringTransformer($options['precision'], $options['type']));
}

/**
Expand Down
Expand Up @@ -29,7 +29,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
$options['second_options']['required'] = $options['required'];

$builder
->appendClientTransformer(new ValueToDuplicatesTransformer(array(
->addViewTransformer(new ValueToDuplicatesTransformer(array(
$options['first_name'],
$options['second_name'],
)))
Expand Down
Expand Up @@ -24,7 +24,7 @@ class TextType extends AbstractType
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->appendClientTransformer(new ValueToStringTransformer())
->addViewTransformer(new ValueToStringTransformer())
;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Form/Extension/Core/Type/TimeType.php
Expand Up @@ -37,7 +37,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
}

if ('single_text' === $options['widget']) {
$builder->appendClientTransformer(new DateTimeToStringTransformer($options['data_timezone'], $options['user_timezone'], $format));
$builder->addViewTransformer(new DateTimeToStringTransformer($options['data_timezone'], $options['user_timezone'], $format));
} else {
$hourOptions = $minuteOptions = $secondOptions = array();

Expand Down Expand Up @@ -92,7 +92,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
$builder->add('second', $options['widget'], $secondOptions);
}

$builder->appendClientTransformer(new DateTimeToArrayTransformer($options['data_timezone'], $options['user_timezone'], $parts, 'text' === $options['widget']));
$builder->addViewTransformer(new DateTimeToArrayTransformer($options['data_timezone'], $options['user_timezone'], $parts, 'text' === $options['widget']));
}

if ('string' === $options['input']) {
Expand Down
Expand Up @@ -80,15 +80,15 @@ public function validate($form, Constraint $constraint)
}
}
} else {
$clientDataAsString = is_scalar($form->getClientData())
? (string) $form->getClientData()
: gettype($form->getClientData());
$clientDataAsString = is_scalar($form->getViewData())
? (string) $form->getViewData()
: gettype($form->getViewData());

// Mark the form with an error if it is not synchronized
$this->context->addViolation(
$config->getOption('invalid_message'),
array('{{ value }}' => $clientDataAsString),
$form->getClientData(),
$form->getViewData(),
null,
Form::ERR_INVALID
);
Expand Down

0 comments on commit bec8015

Please sign in to comment.