Hi guys, I am creating a ModelAdmin in which I will manage DataObjects, e.g. 'Project'. Each Project has a $has_many of Images that will be managed by an ImageDataObjectManager.
I would like, upon creating a Project, to have the set of images in its unique subfolder, as there could be hundreds of Projects in my ModelAdmin.
Now, when I create a new Project in ModelAdmin, none of the fields are set, so the IDOM's setUploadFolder method doesn't know $this->Folder, because it doesn't exist yet. How do I approach this? A few thoughts:
a) IDOM is present and visible before I save the Project. That means I can technically upload images before I've saved. I could make IDOM invisible until I've saved and then normally upload the images. By then, the Folder will be known to IDOM.
b) I could just run some kind of a function upon saving the Project object that will move all the Photos, if any, into the appropriate subfolder.
I'm not that good in SS to know what needs to be done in either of the two cases. Any help on this would be appreciated.
class Project extends DataObject {
static $db = array(
...
'Folder' => 'Varchar',
...
);
static $has_many = array (
'Photos' => 'Photo'
);
function getCMSFields() {
$fields=parent::getCMSFields();
...
$photoManager = new ImageDataObjectManager(
$this, // Controller
'Photos', // Source name
'Image', // Source class
'File', // File name on DataObject
array(
'Description'=>'Description'
)
);
$photoManager->setUploadFolder($this->Folder);
$fields->addFieldToTab("Root.Images",$photoManager);
return $fields;
}
}