I have a form type that I use for making a reusable form for uploading a file. It's integrated with Gaufrette and Amazon S3, and works like a charm. I wanted to reuse the same form type for editing / updating.
I created the routing, callback, etc. for the edit. When I reuse the same form type, it breaks on the mapping:
The form's view data is expected to be an instance of class Symfony\Component\HttpFoundation\File\File, but is a(n) string. You can avoid this error by setting the "data_class" option to null or by adding a view transformer that transforms a(n) string to an instance of Symfony\Component\HttpFoundation\File\File.
When I set mapped to false, the form works for update, but doesn't work for the initial creation.
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('name')
->add('path', 'file', array('mapped' => false))
->add('report')
;
}
It seems like the path that's being saved is not able to be mapped to the form, and my work around was to have two form types for upload and creation, but that didn't seem like the right approach.
What's the best way to do this?