Skip to content

Commit

Permalink
merged branch greg0ire/position_switching (PR symfony#4533)
Browse files Browse the repository at this point in the history
Commits
-------

f541a54 [Form] implement force append / prepend

Discussion
----------

implement force append / prepend

See symfony#4494 and symfony#4473

---------------------------------------------------------------------------

by travisbot at 2012-06-09T12:33:07Z

This pull request [passes](http://travis-ci.org/symfony/symfony/builds/1575997) (merged b0ed9b26 into 3bb7dc0).

---------------------------------------------------------------------------

by stof at 2012-06-09T12:53:29Z

@fabpot 👍 for me.

---------------------------------------------------------------------------

by travisbot at 2012-06-09T12:57:54Z

This pull request [passes](http://travis-ci.org/symfony/symfony/builds/1576150) (merged 5e45b5d3 into 3bb7dc0).

---------------------------------------------------------------------------

by travisbot at 2012-06-09T13:41:05Z

This pull request [passes](http://travis-ci.org/symfony/symfony/builds/1576322) (merged d51c5437 into 3bb7dc0).

---------------------------------------------------------------------------

by fabpot at 2012-06-09T14:47:37Z

Can you add a mention in the CHANGELOG please?

---------------------------------------------------------------------------

by greg0ire at 2012-06-09T14:58:25Z

Couldn't find anything relevant to update in the CHANGELOG of the form component, but the UPGRADE file contains something I could update.

---------------------------------------------------------------------------

by travisbot at 2012-06-09T15:06:27Z

This pull request [passes](http://travis-ci.org/symfony/symfony/builds/1576951) (merged 6b45ba66 into 3bb7dc0).

---------------------------------------------------------------------------

by greg0ire at 2012-06-09T15:06:51Z

Squashed all the commits into one.
  • Loading branch information
fabpot committed Jun 9, 2012
2 parents 37678e1 + f541a54 commit dedaa82
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 19 deletions.
6 changes: 3 additions & 3 deletions UPGRADE-2.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -628,12 +628,12 @@
* The following methods in `FormBuilder` were deprecated and have a new
equivalent:
* `prependClientTransformer`: no new equivalent, consider using `addViewTransformer`
* `prependClientTransformer`: `addViewTransformer`, with `true` as second argument
* `appendClientTransformer`: `addViewTransformer`
* `getClientTransformers`: `getViewTransformers`
* `resetClientTransformers`: `resetViewTransformers`
* `prependNormTransformer`: `addModelTransformer`
* `appendNormTransformer`: no new equivalent, consider using `addModelTransformer`
* `appendNormTransformer`: `addModelTransformer`, with `true` as second argument
* `getNormTransformers`: `getModelTransformers`
* `resetNormTransformers`: `resetModelTransformers`
Expand All @@ -643,7 +643,7 @@
Before:
```
$builder->prependClientTransformer(new MyTransformer());
$builder->appendClientTransformer(new MyTransformer());
```
After:
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bridge/Doctrine/Form/Type/DoctrineType.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
if ($options['multiple']) {
$builder
->addEventSubscriber(new MergeDoctrineCollectionListener())
->prependClientTransformer(new CollectionToArrayTransformer())
->addViewTransformer(new CollectionToArrayTransformer(), true)
;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bridge/Propel1/Form/Type/ModelType.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class ModelType extends AbstractType
public function buildForm(FormBuilderInterface $builder, array $options)
{
if ($options['multiple']) {
$builder->prependClientTransformer(new CollectionToArrayTransformer());
$builder->addViewTransformer(new CollectionToArrayTransformer(), true);
}
}

Expand Down
24 changes: 14 additions & 10 deletions src/Symfony/Component/Form/FormConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,13 @@ public function addValidator(FormValidatorInterface $validator)
/**
* {@inheritdoc}
*/
public function addViewTransformer(DataTransformerInterface $viewTransformer)
public function addViewTransformer(DataTransformerInterface $viewTransformer, $forcePrepend = false)
{
$this->viewTransformers[] = $viewTransformer;
if ($forcePrepend) {
array_unshift($this->viewTransformers, $viewTransformer);
} else {
$this->viewTransformers[] = $viewTransformer;
}

return $this;
}
Expand Down Expand Up @@ -222,9 +226,7 @@ public function appendClientTransformer(DataTransformerInterface $viewTransforme
*/
public function prependClientTransformer(DataTransformerInterface $viewTransformer)
{
array_unshift($this->viewTransformers, $viewTransformer);

return $this;
return $this->addViewTransformer($viewTransformer, true);
}

/**
Expand All @@ -243,9 +245,13 @@ public function resetClientTransformers()
/**
* {@inheritdoc}
*/
public function addModelTransformer(DataTransformerInterface $modelTransformer)
public function addModelTransformer(DataTransformerInterface $modelTransformer, $forceAppend = false)
{
array_unshift($this->modelTransformers, $modelTransformer);
if ($forceAppend) {
$this->modelTransformers[] = $modelTransformer;
} else {
array_unshift($this->modelTransformers, $modelTransformer);
}

return $this;
}
Expand All @@ -271,9 +277,7 @@ public function resetModelTransformers()
*/
public function appendNormTransformer(DataTransformerInterface $modelTransformer)
{
$this->modelTransformers[] = $modelTransformer;

return $this;
return $this->addModelTransformer($modelTransformer, true);
}

/**
Expand Down
10 changes: 6 additions & 4 deletions src/Symfony/Component/Form/FormConfigEditorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,19 @@ function addEventSubscriber(EventSubscriberInterface $subscriber);
function addValidator(FormValidatorInterface $validator);

/**
* Appends a transformer to the view transformer chain.
* Appends / prepends a transformer to the view transformer chain.
*
* The transform method of the transformer is used to convert data from the
* normalized to the view format.
* The reverseTransform method of the transformer is used to convert from the
* view to the normalized format.
*
* @param DataTransformerInterface $viewTransformer
* @param Boolean $forcePrepend if set to true, prepend instead of appending
*
* @return self The configuration object.
*/
function addViewTransformer(DataTransformerInterface $viewTransformer);
function addViewTransformer(DataTransformerInterface $viewTransformer, $forcePrepend = false);

/**
* Clears the view transformers.
Expand All @@ -73,18 +74,19 @@ function addViewTransformer(DataTransformerInterface $viewTransformer);
function resetViewTransformers();

/**
* Prepends a transformer to the normalization transformer chain.
* Prepends / appends a transformer to the normalization transformer chain.
*
* The transform method of the transformer is used to convert data from the
* model to the normalized format.
* The reverseTransform method of the transformer is used to convert from the
* normalized to the model format.
*
* @param DataTransformerInterface $modelTransformer
* @param Boolean $forceAppend if set to true, append instead of prepending
*
* @return self The configuration object.
*/
function addModelTransformer(DataTransformerInterface $modelTransformer);
function addModelTransformer(DataTransformerInterface $modelTransformer, $forceAppend = false);

/**
* Clears the normalization transformers.
Expand Down

0 comments on commit dedaa82

Please sign in to comment.