[Form] implement force append / prepend
This commit is contained in:
parent
3bb7dc0bfa
commit
f541a54770
@ -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`
|
||||
|
||||
@ -643,7 +643,7 @@
|
||||
Before:
|
||||
|
||||
```
|
||||
$builder->prependClientTransformer(new MyTransformer());
|
||||
$builder->appendClientTransformer(new MyTransformer());
|
||||
```
|
||||
|
||||
After:
|
||||
|
@ -39,7 +39,7 @@ abstract class DoctrineType extends AbstractType
|
||||
if ($options['multiple']) {
|
||||
$builder
|
||||
->addEventSubscriber(new MergeDoctrineCollectionListener())
|
||||
->prependClientTransformer(new CollectionToArrayTransformer())
|
||||
->addViewTransformer(new CollectionToArrayTransformer(), true)
|
||||
;
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -179,9 +179,13 @@ class FormConfig implements FormConfigEditorInterface
|
||||
/**
|
||||
* {@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;
|
||||
}
|
||||
@ -222,9 +226,7 @@ class FormConfig implements FormConfigEditorInterface
|
||||
*/
|
||||
public function prependClientTransformer(DataTransformerInterface $viewTransformer)
|
||||
{
|
||||
array_unshift($this->viewTransformers, $viewTransformer);
|
||||
|
||||
return $this;
|
||||
return $this->addViewTransformer($viewTransformer, true);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -243,9 +245,13 @@ class FormConfig implements FormConfigEditorInterface
|
||||
/**
|
||||
* {@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;
|
||||
}
|
||||
@ -271,9 +277,7 @@ class FormConfig implements FormConfigEditorInterface
|
||||
*/
|
||||
public function appendNormTransformer(DataTransformerInterface $modelTransformer)
|
||||
{
|
||||
$this->modelTransformers[] = $modelTransformer;
|
||||
|
||||
return $this;
|
||||
return $this->addModelTransformer($modelTransformer, true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -52,7 +52,7 @@ interface FormConfigEditorInterface extends FormConfigInterface
|
||||
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.
|
||||
@ -60,10 +60,11 @@ interface FormConfigEditorInterface extends FormConfigInterface
|
||||
* 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.
|
||||
@ -73,7 +74,7 @@ interface FormConfigEditorInterface extends FormConfigInterface
|
||||
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.
|
||||
@ -81,10 +82,11 @@ interface FormConfigEditorInterface extends FormConfigInterface
|
||||
* 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.
|
||||
|
Reference in New Issue
Block a user