Skip to content
Browse files

Merge pull request #208 from halkyon/upload_assets_changes

Uploads go to "assets/assets" instead of root of assets
  • Loading branch information...
2 parents 832dae2 + 118b28d commit de4f2075342d5a595bae495400937e4d35d07019 @sminnee sminnee committed Oct 10, 2012
Showing with 12 additions and 10 deletions.
  1. +5 −3 code/controllers/AssetAdmin.php
  2. +7 −7 code/controllers/CMSFileAddController.php
View
8 code/controllers/AssetAdmin.php
@@ -478,10 +478,12 @@ public function doAdd($data, $form) {
public function currentPage() {
$id = $this->currentPageID();
if($id && is_numeric($id) && $id > 0) {
- return DataObject::get_by_id('Folder', $id);
- } else {
- return new Folder();
+ $folder = DataObject::get_by_id('Folder', $id);
+ if($folder && $folder->exists()) {
+ return $folder;
+ }
}
+ return new Folder();
}
public function getSiteTreeFor($className, $rootID = null, $childrenMethod = null, $numChildrenMethod = null, $filterFunction = null, $minNodeCount = 30) {
View
14 code/controllers/CMSFileAddController.php
@@ -23,13 +23,13 @@ class CMSFileAddController extends LeftAndMain {
*/
public function currentPage() {
$id = $this->currentPageID();
-
if($id && is_numeric($id) && $id > 0) {
- return DataObject::get_by_id('Folder', $id);
- } else {
- // ID is either '0' or 'root'
- return singleton('Folder');
+ $folder = DataObject::get_by_id('Folder', $id);
+ if($folder && $folder->exists()) {
+ return $folder;
+ }
}
+ return new Folder();
}
/**
@@ -64,12 +64,12 @@ public function getEditForm($id = null, $fields = null) {
$uploadField->removeExtraClass('ss-uploadfield');
$uploadField->setTemplate('AssetUploadField');
- if ($folder->exists() && $folder->getFilename()) {
+ if($folder->exists() && $folder->getFilename()) {
// The Upload class expects a folder relative *within* assets/
$path = preg_replace('/^' . ASSETS_DIR . '\//', '', $folder->getFilename());
$uploadField->setFolderName($path);
} else {
- $uploadField->setFolderName(ASSETS_DIR);
+ $uploadField->setFolderName('/'); // root of the assets
}
$exts = $uploadField->getValidator()->getAllowedExtensions();

0 comments on commit de4f207

Please sign in to comment.
Something went wrong with that request. Please try again.