First, you have to create a valid object from your default file.
To do that, use the Symfony\Component\HttpFoundation\File.
Usage: $file = new File('path/of/your/default/file');
Then, you have to update your form before the data binding is done.
For that, you have two solutions :
1- Use a FormEvent to manually set the file if the field is null. (e.g. PRE_SUBMIT and POST_SUBMIT)
2- Use a prePersist/preUpdate hook in your entity. (Doesn't involves to move your logic, the unmapped property 'attachment' should already exists in your entity)
For the option 1, see the Dynamic form modification chapter of the cookbook and look for the appropriated event (the documentation will give the informations to choose it).
For the 2, see the Events chapterof Doctrine documentation.
Something like the following should do the job :
/**
* @ORM\HasLifecycleCallbacks
*/
class YourEntity {
/**
*
* @ORM\PrePersist
* @ORM\PreUpdate
*/
public function manageFile()
{
if ($this->attachment === null) {
$file = new File('path/of/your/default/file');
$this->setAttachment($file);
}
}
}
I hope it's sufficient for you.