BUGFIX Fixed CMSFileAddController upload in custom folders

This commit is contained in:
Ingo Schommer 2012-03-02 15:43:22 +01:00
parent 467db5146b
commit 7125af918d

View File

@ -33,13 +33,19 @@ class CMSFileAddController extends AssetAdmin {
$uploadField->removeExtraClass('ss-uploadfield'); $uploadField->removeExtraClass('ss-uploadfield');
$uploadField->setTemplate('AssetUploadField'); $uploadField->setTemplate('AssetUploadField');
if ($folder->exists() && $folder->getFilename()) { if ($folder->exists() && $folder->getFilename()) {
$uploadField->setFolderName($this->currentPage()->getFilename()); // The Upload class expects a folder relative *within* assets/
$path = preg_replace('/^' . ASSETS_DIR . '\//', '', $folder->getFilename());
$uploadField->setFolderName($path);
} }
$form = new Form($this, 'getEditForm', new FieldList($uploadField), new FieldList()); $form = new Form(
$this,
'getEditForm',
new FieldList($uploadField, new HiddenField('ID')),
new FieldList()
);
$form->addExtraClass('center cms-edit-form ' . $this->BaseCSSClasses()); $form->addExtraClass('center cms-edit-form ' . $this->BaseCSSClasses());
$form->setTemplate($this->getTemplatesWithSuffix('_EditForm')); $form->setTemplate($this->getTemplatesWithSuffix('_EditForm'));
$form->Fields()->push( $form->Fields()->push(
new LiteralField( new LiteralField(
'BackLink', 'BackLink',
@ -50,6 +56,7 @@ class CMSFileAddController extends AssetAdmin {
) )
) )
); );
$form->loadDataFrom($folder);
return $form; return $form;
} }