Reputation: 40499
In SilverStripe 3.1 I have a class extending DataObject
that has_one Image
.
How can I specify a particular folder for the image files to be uploaded into when the user uploads an image from the CMS?
Upvotes: 0
Views: 635
Reputation: 40499
In my class getCMSFields function, I got the UploadField for the Image then called the setFolderName function:
class BannerImage extends DataObject {
private static $has_one = array(
'Page' => 'Page',
'Image' => 'Image'
);
public function getCMSFields() {
$fields = parent::getCMSFields();
/** @var UploadField $uploadField */
$uploadField = $fields->fieldByName('Root.Main.Image');
$uploadField->setFolderName("banners");
...
Upvotes: 2