Permalink
Browse files

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
  • Loading branch information...
1 parent 6aae0aa commit 5738c57d8a40a3617ce1e6370dc353d3a0d9b836 @chillu chillu committed Nov 21, 2009
Showing with 12 additions and 18 deletions.
  1. +12 −18 code/AssetAdmin.php
View
@@ -303,6 +303,9 @@ function getEditForm($id = null) {
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 @@ function AddForm() {
/**
* 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 @@ public function doAdd() {
}
$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);

0 comments on commit 5738c57

Please sign in to comment.