Hello,
I am facing a recurrent problem using Silverstripe, and I was wondering if you have a magic solution for me.
Everytime I have a DataObject with images, I must to be sure the current DataObject has not an empty ID. It forces my customer to click on the button "create" first, and then add images.
So I want to perform a create action immediatly on the click of the "add" GriedField button, and redirect then the customer to the edition of the DataObject.
For now, I try to call the write() method in the getCMSFields() when it has an empty ID. But It's doesn't work, and it's ugly. Do you have any idea how to do this ? I am working with Silverstripe v3.0.2.
public function getCMSFields(){
if(empty($this->ID)){
$this->ID = $this->write();
// Reload page here ??
}
$fields = new FieldList();
$imageField = new UploadField('image', 'Illustration');
$imageField->allowedExtensions = array('jpg', 'gif', 'png', 'JPG', 'GIF', 'PNG');
$fields->push($imageField);
return $fields;
}
Thanks a lot for your help !