1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
class DMSDocumentAdmin extends ModelAdmin |
|
|
|
|
4
|
|
|
{ |
5
|
|
|
private static $managed_models = array( |
|
|
|
|
6
|
|
|
'DMSDocument', |
7
|
|
|
'DMSDocumentSet' |
8
|
|
|
); |
9
|
|
|
|
10
|
|
|
private static $url_segment = 'documents'; |
|
|
|
|
11
|
|
|
|
12
|
|
|
private static $menu_title = 'Documents'; |
|
|
|
|
13
|
|
|
|
14
|
|
|
private static $menu_icon = 'dms/images/app_icons/drawer.png'; |
|
|
|
|
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Remove the default "add" button and replace it with a customised version for DMS |
18
|
|
|
* |
19
|
|
|
* @return CMSForm |
20
|
|
|
*/ |
21
|
|
|
public function getEditForm($id = null, $fields = null) |
22
|
|
|
{ |
23
|
|
|
/** @var CMSForm $form */ |
24
|
|
|
$form = parent::getEditForm($id, $fields); |
25
|
|
|
$gridField = $form->Fields()->fieldByName($this->sanitiseClassName($this->modelClass)); |
26
|
|
|
return $this->modifyGridField($form, $gridField); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* If the GridField is for DMSDocument then add a custom "add" button. If it's for DMSDocumentSet then |
31
|
|
|
* update the display fields to include some extra columns that are only for this ModelAdmin, so cannot |
32
|
|
|
* be added directly to the model's display fields. |
33
|
|
|
* |
34
|
|
|
* @param CMSForm $form |
35
|
|
|
* @param GridField $gridField |
36
|
|
|
* @return CMSForm |
37
|
|
|
*/ |
38
|
|
|
protected function modifyGridField(CMSForm $form, GridField $gridField) |
39
|
|
|
{ |
40
|
|
|
$gridFieldConfig = $gridField->getConfig(); |
41
|
|
|
|
42
|
|
|
if ($this->modelClass === 'DMSDocument') { |
43
|
|
|
$gridFieldConfig->removeComponentsByType('GridFieldAddNewButton'); |
44
|
|
|
$gridFieldConfig->addComponent(new DMSGridFieldAddNewButton('buttons-before-left'), 'GridFieldExportButton'); |
45
|
|
|
} elseif ($this->modelClass === 'DMSDocumentSet') { |
46
|
|
|
$gridFieldConfig->removeComponentsByType('GridFieldAddNewButton'); |
47
|
|
|
|
48
|
|
|
$dataColumns = $gridFieldConfig->getComponentByType('GridFieldDataColumns'); |
49
|
|
|
$fields = $dataColumns->getDisplayFields($gridField); |
50
|
|
|
$fields = array('Title' => 'Title', 'Page.Title' => 'Page') + $fields; |
51
|
|
|
$dataColumns->setDisplayFields($fields); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
return $form; |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.