mirror of
https://github.com/silverstripe/silverstripe-reports
synced 2024-10-22 09:05:53 +00:00
BUG setFolderName in CMSFileAddController should default to the root
setFolderName expects a folder name relative to the root. Specifying ASSETS_DIR will create a duplicate folder called "assets", so the file gets uploaded into "assets/assets". Specifying "/" means the file will get uploaded into the root instead, which is correct.
This commit is contained in:
parent
4af60dfee6
commit
118b28dea1
@ -478,11 +478,13 @@ JS
|
|||||||
public function currentPage() {
|
public function currentPage() {
|
||||||
$id = $this->currentPageID();
|
$id = $this->currentPageID();
|
||||||
if($id && is_numeric($id) && $id > 0) {
|
if($id && is_numeric($id) && $id > 0) {
|
||||||
return DataObject::get_by_id('Folder', $id);
|
$folder = DataObject::get_by_id('Folder', $id);
|
||||||
} else {
|
if($folder && $folder->exists()) {
|
||||||
return new Folder();
|
return $folder;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return new Folder();
|
||||||
|
}
|
||||||
|
|
||||||
function getSiteTreeFor($className, $rootID = null, $childrenMethod = null, $numChildrenMethod = null, $filterFunction = null, $minNodeCount = 30) {
|
function getSiteTreeFor($className, $rootID = null, $childrenMethod = null, $numChildrenMethod = null, $filterFunction = null, $minNodeCount = 30) {
|
||||||
if (!$childrenMethod) $childrenMethod = 'ChildFolders';
|
if (!$childrenMethod) $childrenMethod = 'ChildFolders';
|
||||||
|
@ -23,14 +23,14 @@ class CMSFileAddController extends LeftAndMain {
|
|||||||
*/
|
*/
|
||||||
public function currentPage() {
|
public function currentPage() {
|
||||||
$id = $this->currentPageID();
|
$id = $this->currentPageID();
|
||||||
|
|
||||||
if($id && is_numeric($id) && $id > 0) {
|
if($id && is_numeric($id) && $id > 0) {
|
||||||
return DataObject::get_by_id('Folder', $id);
|
$folder = DataObject::get_by_id('Folder', $id);
|
||||||
} else {
|
if($folder && $folder->exists()) {
|
||||||
// ID is either '0' or 'root'
|
return $folder;
|
||||||
return singleton('Folder');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return new Folder();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return fake-ID "root" if no ID is found (needed to upload files into the root-folder)
|
* Return fake-ID "root" if no ID is found (needed to upload files into the root-folder)
|
||||||
@ -64,12 +64,12 @@ class CMSFileAddController extends LeftAndMain {
|
|||||||
$uploadField->removeExtraClass('ss-uploadfield');
|
$uploadField->removeExtraClass('ss-uploadfield');
|
||||||
$uploadField->setTemplate('AssetUploadField');
|
$uploadField->setTemplate('AssetUploadField');
|
||||||
|
|
||||||
if ($folder->exists() && $folder->getFilename()) {
|
if($folder->exists() && $folder->getFilename()) {
|
||||||
// The Upload class expects a folder relative *within* assets/
|
// The Upload class expects a folder relative *within* assets/
|
||||||
$path = preg_replace('/^' . ASSETS_DIR . '\//', '', $folder->getFilename());
|
$path = preg_replace('/^' . ASSETS_DIR . '\//', '', $folder->getFilename());
|
||||||
$uploadField->setFolderName($path);
|
$uploadField->setFolderName($path);
|
||||||
} else {
|
} else {
|
||||||
$uploadField->setFolderName(ASSETS_DIR);
|
$uploadField->setFolderName('/'); // root of the assets
|
||||||
}
|
}
|
||||||
|
|
||||||
$exts = $uploadField->getValidator()->getAllowedExtensions();
|
$exts = $uploadField->getValidator()->getAllowedExtensions();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user