Skip to content

Commit

Permalink
MINOR Fixed ParentID setting in AssetAdmin->doAdd() and using instead of
Browse files Browse the repository at this point in the history
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@92812 467b73ca-7a2a-4603-9d3b-597d59a354a9
  • Loading branch information
chillu committed Nov 21, 2009
1 parent 6aae0aa commit 5738c57
Showing 1 changed file with 12 additions and 18 deletions.
30 changes: 12 additions & 18 deletions code/AssetAdmin.php
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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);
Expand Down

0 comments on commit 5738c57

Please sign in to comment.