In my Doctrine entity, which is data_class
for my form I have a file property defined like this:
/**
* Image.
*
* @Assert\NotBlank
* @Assert\File
* @Assert\Image(minWidth="138", minHeight="96")
*/
protected $file;
Also, added it to form type with ->add('file', 'file')
...
Creating entity works perfect, but the problem is when I use form to update this entity. It asks for file again, since it has @Assert\NotBlank. Since I have other fields in this form, I don't want to reupload image on every update.
When I remove @Assert\NotBlank, everithing works fine, but I want this file field to be mandatory.
Any idea?
if (null !== $this->getId())
. You can check my gist gist.github.com/3066507. It was even fancyer in Symfony 2.0 when you can pass in context to validator gist.github.com/3066488. Thanks again. – Bleier