Thanks for your reply Aram.
I've made some progress, but I'm stuck again. First, I realised that has_many relation only works if the other Object has 'has_one' defined, so I changed the relation to many_many.
Then I decided not to subclass 'File' DataObject but instead create a DataExtension. With It's method updateCMSFields I can control which fields are displayed in the create new 'File' Form.
Then I tried adding the new UploadField to this Form (via the updateCMSFields), but here comes the problem. UploadField requires a relation to the parent Object which i have no idea how to get from the DataExtension class.
class GradivoFile extends DataExtension {
public static $db = array();
public function updateCMSFields(FieldList $fields) {
$fields->addFieldToTab("Root.Main",
new UploadField("Datoteka", "Datoteka", $this->owner)
);
}
}
And in my_config.php i have:
Object::add_extension('File', 'GradivoFile');
The problem with the code is that $this->owner returns a 'File' object instead the Object with many_many defined (in my case Gradivo, which means Material in Slovene). So when i try uploading file with the form there is an error.
I've tried to overcome this problem but i can't seem to understand how to get the data from silverstripe controllers. The only way i can think of is from the URL but this sounds a bit to lame, so I didn't even try it:
URL: .../admin/gradiva/Gradivo/EditForm/field/Gradivo/item/1/ItemEditForm/field/Datoteka/item/new