So, I have this DataObject:
class Product extends DataObject {
static $db = array(
'Name' => 'Varchar',
'Price' => 'Int',
'InitialQuantity' => 'Int',
'Content' => 'HTMLText',
);
// (...)
static $has_many = array(
'Picture' => 'Image'
);
// (...)
and getCMSFields like this:
public function getCMSFields() {
$fields = parent::getCMSFields();
$field = new UploadField('Picture', 'Zdjęcie');
$field->allowedExtensions = array('jpg', 'gif', 'png');
$fields->addFieldToTab('Root.Main', $field);
return $fields;
}
The ModelAdmin for this is a default one. Now, when I upload an image file from my computer, it ends up at /assets/Upload/file.jpg on the server and it is all right. But the URL shown in ModelAdmin is /assets/file.jpg and after the upload completes, the thumbnail disappears.
I've debugged through it and found out, that in UploadField.upload method, around line 506 is a line:
$this->attachFile($file);
Before it, everything's fine, after it the filename and URL is broken (e.g. Upload part of the path is missing, just /assets/file.jpg is there). Going deeper in SilverStripe code, I've found out that it is broken at HasManyList.add method, where around line 55 is a line:
$item->$fk = $this->foreignID;
Before it everything's fine, after it the filename and URL is broken.
It is too magic code for me to fix it, would anyone be able to offer help with this? Am I doing something wrong or is it a bug?