From 5738c57d8a40a3617ce1e6370dc353d3a0d9b836 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Sat, 21 Nov 2009 03:19:29 +0000 Subject: [PATCH] MINOR Fixed ParentID setting in AssetAdmin->doAdd() and using instead of git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@92812 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- code/AssetAdmin.php | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/code/AssetAdmin.php b/code/AssetAdmin.php index 9b421dd9..3970dffc 100755 --- a/code/AssetAdmin.php +++ b/code/AssetAdmin.php @@ -303,6 +303,9 @@ HTML; if($record) { $fields = $record->getCMSFields(); + // Required for file tree setup + if(!$fields->dataFieldByName('ParentID')) $fields->push(new HiddenField('ParentID')); + $actions = new FieldSet(); // Only show save button if not 'assets' folder @@ -536,13 +539,13 @@ JS; /** * Add a new folder and return its details suitable for ajax. */ - public function doAdd() { - $parent = ($_REQUEST['ParentID'] && is_numeric($_REQUEST['ParentID'])) ? (int)$_REQUEST['ParentID'] : 0; - $name = (isset($_REQUEST['Name'])) ? basename($_REQUEST['Name']) : _t('AssetAdmin.NEWFOLDER',"NewFolder"); + public function doAdd($data, $form) { + $parentID = (isset($data['ParentID']) && is_numeric($data['ParentID'])) ? (int)$data['ParentID'] : 0; + $name = (isset($data['Name'])) ? basename($data['Name']) : _t('AssetAdmin.NEWFOLDER',"NewFolder"); - if($parent) { - $parentObj = DataObject::get_by_id('File', $parent); - if(!$parentObj || !$parentObj->ID) $parent = 0; + if($parentID) { + $parentObj = DataObject::get_by_id('File', $parentID); + if(!$parentObj || !$parentObj->ID) $parentID = 0; } // Get the folder to be created @@ -555,21 +558,12 @@ JS; } $p = new Folder(); - $p->ParentID = $parent; - $p->Name = $p->Title = basename($filename); - - // Ensure uniqueness - $i = 2; - $baseFilename = substr($p->Filename, 0, -1) . '-'; - while(file_exists($p->FullPath)) { - $p->Filename = $baseFilename . $i . '/'; - $i++; - } - + $p->ParentID = $parentID; + $p->Name = $p->Title = basename($filename); $p->write(); // Used in TinyMCE inline folder creation - if(isset($_REQUEST['returnID'])) { + if(isset($data['returnID'])) { return $p->ID; } else { $form = $this->getEditForm($p->ID);