<p dir="auto">Symfony: 3.2</p>
<p dir="auto">What is the reasoning behind checking if the viewdata is an instance of the data_class in <a href="https://github.com/symfony/form/blob/master/Form.php#L358">Form.php</a>? Is this check preventing some situations that would be bad?</p>
<p dir="auto">I got the corresponding LogicException in a situation that issued some strange demands on my code. Simplest code is in the zip in attachment: a ValueObject that encapsulates a string, and a formtype using this VO.</p>
<p dir="auto">I used a ModelTransformer to convert my data from string to VO and back. The error demands that I set my data_class to null, or add a ViewTransformer. I added the ViewTransformer, as a ReversedTransformer from my ModelTransformer (not sure why ViewData would need to be an object). That did not work, so I changed the data_class to another option "data_class_my", to test if this would help. It did, untill I added some data to my formtype. I had to explicitly set the data_class to null, which makes no sense to do, as all seems to work if I simply remove the if block in Form.php on line 358.</p>
<ol dir="auto">
<li>Why would Symfony tell me to convert my norm data to view data which is an object, when the view data I receive from the submitted form is never going to be an object? It seems unneeded to actually add a view data transformer there.</li>
<li>Why can I not use data_class to tell my formtype to convert it to an object?</li>
</ol>
<p dir="auto">I know I can do this some other way with datamappers, DTO's, and so on..., but I'm really puzzled why this is not working. Is this actually a bug, or is it avoiding some more terrible situations?</p>
<p dir="auto"><a href="https://github.com/symfony/symfony/files/646682/Symfony.zip">Symfony.zip</a></p>
<p dir="auto">Did a little digging, <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/webmozart/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/webmozart">@webmozart</a>, do you remember what is going on here? It was added in 2012, so might be hard to remember...</p>
<p dir="auto">why cannot customize about this.</p>