Silverstripe Version: 4.9
Question: There is any way to set default value for UploadField?
I have a question about setting default image for my DataObject. I have in database photo that i want to add as default for my input(UploadField) i want to load the Image to UploadField and if user save form simply save this image but if someone want to change img a want to save this image saved by user. Below is my code.
private static $has_one = array(
'Image' => Image::class,
);
public function getCMSFields()
{
$fields = new FieldList();
$img = new UploadField('Image');
$img->setFolderName('path/to/my/folder');
$img->getValidator()->setAllowedExtensions(array('jpg', 'gif', 'png'));
$fields->push($img);
(Here i have logic for download the image object that i want to use as default image $Image is my object)
$fields->dataFieldByName('Image')->setValue($Image->ID);
}
Im trying too the other option as documentation say:
$fields->dataFieldByName('Image')->setValue(array('Files'=>array($Image->ID)));
Any way the image not loaded to my admin page there is any way to achive this?
Thank you in advance for help