silverstripe-dms/code/DMSSiteTreeExtension.php
Normann Lou 09a8229ec0 APICHANGE: change DMSDocumentInterface::downloadLink() to DMSDocumentInterface::getDownloadLink() so that a $DownloadLink could be used as a field to make GridField for DMSDocument to have a formatted linkable column
ENHANCEMENT: make "Filename" column of a GridField clickable hence make the document downlaodable.
ENHANCEMENT: make "Last Changed" column show as a "Ago" format, ie. 'A day ago' or 'there months ago'.
2012-08-01 12:35:44 +12:00

49 lines
1.5 KiB
PHP

<?php
class DMSSiteTreeExtension extends DataExtension {
static $belongs_many_many = array(
'Documents' => 'DMSDocument'
);
function updateCMSFields(FieldList $fields){
// Document listing
$gridFieldConfig = GridFieldConfig::create()->addComponents(
new GridFieldToolbarHeader(),
new GridFieldFilterHeader(),
new GridFieldSortableHeader(),
new GridFieldDataColumns(),
new GridFieldPaginator(15),
new GridFieldEditButton(),
new GridFieldDeleteAction(),
new GridFieldDetailForm()
//GridFieldLevelup::create($folder->ID)->setLinkSpec('admin/assets/show/%d')
);
$modelClass = DMS::$modelClass;
$gridFieldConfig->getComponentByType('GridFieldDataColumns')->setDisplayFields($modelClass::$display_fields)
->setFieldCasting(array('LastChanged'=>"Date->Ago"))
->setFieldFormatting(array('FilenameWithoutID'=>'<a target=\'_blank\' class=\'file-url\' href=\'$DownloadLink\'>$FilenameWithoutID</a>'));
$gridField = GridField::create(
'Documents',
false,
$this->owner->Documents(),
$gridFieldConfig
);
$uploadBtn = new LiteralField(
'UploadButton',
sprintf(
'<a class="ss-ui-button ss-ui-action-constructive cms-panel-link" data-pjax-target="Content" data-icon="add" href="%s">%s</a>',
Controller::join_links(singleton('DMSDocumentAddController')->Link(), '?ID=' . $this->owner->ID),
"Add Document"
)
);
$fields->addFieldsToTab(
'Root.Documents',
array(
$uploadBtn,
$gridField
)
);
}
}