getViewData vs. getNormData and DataTransformers - different results depending on context

被刻印的时光 ゝ 提交于 2019-12-11 06:57:31

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!