Hi,

First of all, the new Form component is awesome.

But now in real contexts, i see some problematic limitations.
I started two projects for clients and face exactly the same issue in both : 
The need of extra fields in a Form.

First example : an user profile with an avatar.
Typically you'll need to store an URL to an image for the avatar, the entity 
should look like :

class UserProfile
{
     protected $pictureUrl;
}

You'll surely need to resize and move the uploaded image before saving the 
URL.
To do so, you need a FileType which returns an UploadedFile object :

$builder->add('pictureUrl', 'file', array(
    'type' => 'file',
    'required' => false,
));

The thing is, you can't map the pictureUrl property because it's just meant 
to store the URL, and if a profile already has a pictureUrl it would be 
replaced during data binding.

So, you need an extra field just to handle the file :

$builder->add('pictureFile', 'file', array(
    'type' => 'file',
    'required' => false,
));

And then, after processing the uploaded file, you should populate the 
pictureUrl property by hand.

But you can't add fields that doesn't exist in your object as a property, so 
you MUST add the pictureFile property to the UserProfile object.
That's is not really a thing the domain should be aware of.

Other example : you want to add a checkbox "Delete this image" next to the 
avatar field.

This has typically nothing to do with your domain object, pure application 
logic. You receive the posted data, if the checkbox input is present you 
erase the pictureUrl property by hand.
But once again, you can't add this extra field to the Form Type.

Maybe i don't understand the form system enough and it's possible but not 
documented yet. Maybe it's not, don't know.
But that's really a common use case and not the only one where your would 
need extra fields.


Benjamin.

-- 
If you want to report a vulnerability issue on symfony, please send it to 
security at symfony-project.com

You received this message because you are subscribed to the Google
Groups "symfony developers" group.
To post to this group, send email to symfony-devs@googlegroups.com
To unsubscribe from this group, send email to
symfony-devs+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/symfony-devs?hl=en

Reply via email to