Description
Symfony: 3.2
What is the reasoning behind checking if the viewdata is an instance of the data_class in Form.php? Is this check preventing some situations that would be bad?
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.
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.
- 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.
- Why can I not use data_class to tell my formtype to convert it to an object?
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?
Did a little digging, @webmozart, do you remember what is going on here? It was added in 2012, so might be hard to remember...