2017-05-03 03:26:17 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class DMSDocumentAdmin extends ModelAdmin
|
|
|
|
{
|
|
|
|
private static $managed_models = array(
|
2017-05-29 00:15:21 +02:00
|
|
|
'DMSDocument',
|
|
|
|
'DMSDocumentSet'
|
2017-05-03 03:26:17 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
private static $url_segment = 'documents';
|
|
|
|
|
|
|
|
private static $menu_title = 'Documents';
|
|
|
|
|
2017-05-22 04:06:06 +02:00
|
|
|
private static $menu_icon = 'dms/images/app_icons/drawer.png';
|
|
|
|
|
2017-05-03 03:26:17 +02:00
|
|
|
/**
|
|
|
|
* Remove the default "add" button and replace it with a customised version for DMS
|
|
|
|
*
|
|
|
|
* @return CMSForm
|
|
|
|
*/
|
|
|
|
public function getEditForm($id = null, $fields = null)
|
|
|
|
{
|
|
|
|
/** @var CMSForm $form */
|
|
|
|
$form = parent::getEditForm($id, $fields);
|
2017-05-29 00:15:21 +02:00
|
|
|
$gridField = $form->Fields()->fieldByName($this->sanitiseClassName($this->modelClass));
|
|
|
|
return $this->modifyGridField($form, $gridField);
|
|
|
|
}
|
2017-05-03 03:26:17 +02:00
|
|
|
|
2017-05-29 00:15:21 +02:00
|
|
|
/**
|
|
|
|
* If the GridField is for DMSDocument then add a custom "add" button. If it's for DMSDocumentSet then
|
|
|
|
* update the display fields to include some extra columns that are only for this ModelAdmin, so cannot
|
|
|
|
* be added directly to the model's display fields.
|
|
|
|
*
|
|
|
|
* @param CMSForm $form
|
|
|
|
* @param GridField $gridField
|
|
|
|
* @return CMSForm
|
|
|
|
*/
|
|
|
|
protected function modifyGridField(CMSForm $form, GridField $gridField)
|
|
|
|
{
|
|
|
|
$gridFieldConfig = $gridField->getConfig();
|
|
|
|
|
|
|
|
if ($this->modelClass === 'DMSDocument') {
|
|
|
|
$gridFieldConfig->removeComponentsByType('GridFieldAddNewButton');
|
|
|
|
$gridFieldConfig->addComponent(new DMSGridFieldAddNewButton('buttons-before-left'), 'GridFieldExportButton');
|
|
|
|
} elseif ($this->modelClass === 'DMSDocumentSet') {
|
|
|
|
$dataColumns = $gridFieldConfig->getComponentByType('GridFieldDataColumns');
|
|
|
|
$fields = $dataColumns->getDisplayFields($gridField);
|
|
|
|
$fields = array('Title' => 'Title', 'Page.Title' => 'Page') + $fields;
|
|
|
|
$dataColumns->setDisplayFields($fields);
|
|
|
|
}
|
2017-05-03 03:26:17 +02:00
|
|
|
|
|
|
|
return $form;
|
|
|
|
}
|
|
|
|
}
|