Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Form] ViewData from a submitted form is not an object #20880

Copy link
Copy link
Closed
@MetalArend

Description

@MetalArend
Issue body actions

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.

  1. 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.
  2. 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?

Symfony.zip

Did a little digging, @webmozart, do you remember what is going on here? It was added in 2012, so might be hard to remember...

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.