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( |
45
|
|
|
new DMSGridFieldAddNewButton('buttons-before-left'), |
46
|
|
|
'GridFieldExportButton' |
47
|
|
|
); |
48
|
|
|
} elseif ($this->modelClass === 'DMSDocumentSet') { |
49
|
|
|
$gridFieldConfig->removeComponentsByType('GridFieldAddNewButton'); |
50
|
|
|
|
51
|
|
|
$dataColumns = $gridFieldConfig->getComponentByType('GridFieldDataColumns'); |
52
|
|
|
$fields = $dataColumns->getDisplayFields($gridField); |
53
|
|
|
$fields = array('Title' => 'Title', 'Page.Title' => 'Page') + $fields; |
54
|
|
|
$dataColumns->setDisplayFields($fields) |
55
|
|
|
->setFieldFormatting( |
56
|
|
|
array( |
57
|
|
|
'Page.Title' => function ($value, $item) { |
58
|
|
|
// Link a page click directly to the page click to the DocumentSets tab |
59
|
|
|
if ($page = SiteTree::get()->byID($item->PageID)) { |
60
|
|
|
$link = CMSMain::create()->LinkPageEdit($item->PageID); |
61
|
|
|
return sprintf( |
62
|
|
|
"<a href='%s#Root_DocumentSets%s'>$value</a>", |
63
|
|
|
$link, |
64
|
|
|
$page->DocumentSets()->count() |
65
|
|
|
); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
) |
69
|
|
|
); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
return $form; |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|
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.