问题
I have a form with several fields.
Then I bound DataTransformer
to the one of them. Transformer works correctly if I get data getViewData
and getNormData
.
But if I issue these methods on whole form, data processed by transformers are completely ignored.
In Form
data is being overwritten due to the:
$childrenIterator = new InheritDataAwareIterator($this->children);
$childrenIterator = new \RecursiveIteratorIterator($childrenIterator);
$this->config->getDataMapper()->mapFormsToData($childrenIterator, $viewData);
My mapper is PropertyPathMapper
. Unfortunately, it bases on getData
method of each child.
Is it possible to bypass viewData
overwrite / achieve correctly transformed data without writing a global transformer?
回答1:
a workaround:
$data = array();
foreach ($form->all() as $k => $el) {
$data[$k] = $el->getData(); // or getNormData or getViewData
}
Unfortunately I have no solution.
The current behaviour is not what I expected. It should at least be mentioned in the symfony cookbook.
As you see I have the same problem. I wrote a test case to be sure that I do not misunderstand how the transformers work. I found your question later.
my test case: https://github.com/SimonHeimberg/SymfonyFormForm_DataTransformer_Demo
来源:https://stackoverflow.com/questions/36940228/getviewdata-vs-getnormdata-and-datatransformers-different-results-depending-o