ENHANCEMENT: Extensions are now the main method of providing custom functionality, replacing subclassing DMSDocument

This commit is contained in:
Andrew O'Neil 2012-08-21 11:31:53 +12:00
parent 3fea76c83a
commit 5150e66de3
3 changed files with 7 additions and 9 deletions

View File

@ -6,11 +6,6 @@ class DMS implements DMSInterface {
//How many documents to store in a single folder. The square of this number is the maximum number of documents. //How many documents to store in a single folder. The square of this number is the maximum number of documents.
//The number should be a multiple of 10 //The number should be a multiple of 10
static $dmsFolderSize = 1000; static $dmsFolderSize = 1000;
static $modelClass = 'DMSDocument';
static function set_model_class($className){
self::$modelClass = $className;
}
/** /**
@ -59,8 +54,7 @@ class DMS implements DMSInterface {
$filePath = self::transform_file_to_file_path($file); $filePath = self::transform_file_to_file_path($file);
//create a new document and get its ID //create a new document and get its ID
$modelClass = self::$modelClass; $doc = new DMSDocument();
$doc = new $modelClass();
$doc->write(); $doc->write();
$doc->storeDocument($filePath); $doc->storeDocument($filePath);

View File

@ -556,6 +556,9 @@ class DMSDocument extends DataObject implements DMSDocumentInterface {
$uploadField->addExtraClass('replace'), $uploadField->addExtraClass('replace'),
$pagesGrid->addExtraClass('find-usage') $pagesGrid->addExtraClass('find-usage')
)->setName("ActionsPanel")->addExtraClass('dmsupload ss-uploadfield')); )->setName("ActionsPanel")->addExtraClass('dmsupload ss-uploadfield'));
$this->extend('updateCMSFields', $fields);
return $fields; return $fields;
} }

View File

@ -22,8 +22,9 @@ class DMSSiteTreeExtension extends DataExtension {
new GridFieldDetailForm() new GridFieldDetailForm()
//GridFieldLevelup::create($folder->ID)->setLinkSpec('admin/assets/show/%d') //GridFieldLevelup::create($folder->ID)->setLinkSpec('admin/assets/show/%d')
); );
$modelClass = DMS::$modelClass;
$gridFieldConfig->getComponentByType('GridFieldDataColumns')->setDisplayFields($modelClass::$display_fields) singleton('DMSDocument');
$gridFieldConfig->getComponentByType('GridFieldDataColumns')->setDisplayFields(Config::inst()->get('DMSDocument', 'display_fields'))
->setFieldCasting(array('LastChanged'=>"Date->Ago")) ->setFieldCasting(array('LastChanged'=>"Date->Ago"))
->setFieldFormatting(array('FilenameWithoutID'=>'<a target=\'_blank\' class=\'file-url\' href=\'$DownloadLink\'>$FilenameWithoutID</a>')); ->setFieldFormatting(array('FilenameWithoutID'=>'<a target=\'_blank\' class=\'file-url\' href=\'$DownloadLink\'>$FilenameWithoutID</a>'));