1 | <?php |
||
6 | class DMSSiteTreeExtension extends DataExtension |
||
7 | { |
||
8 | private static $has_many = array( |
||
9 | 'DocumentSets' => 'DMSDocumentSet' |
||
10 | ); |
||
11 | |||
12 | public function updateCMSFields(FieldList $fields) |
||
13 | { |
||
14 | // Ability to disable document sets for a Page |
||
15 | if (!$this->owner->config()->get('documents_enabled')) { |
||
16 | return; |
||
17 | } |
||
18 | |||
19 | // Hides the DocumentSets tab if the user has no permisions |
||
20 | if (!Permission::checkMember( |
||
21 | Member::currentUser(), |
||
22 | array('ADMIN', 'CMS_ACCESS_DMSDocumentAdmin') |
||
23 | ) |
||
24 | ) { |
||
25 | return; |
||
26 | } |
||
27 | |||
28 | $gridField = GridField::create( |
||
29 | 'DocumentSets', |
||
30 | false, |
||
31 | $this->owner->DocumentSets(), //->Sort('DocumentSort'), |
||
32 | $config = new GridFieldConfig_RelationEditor |
||
33 | ); |
||
34 | $gridField->addExtraClass('documentsets'); |
||
35 | |||
36 | // Only show document sets in the autocompleter that have not been assigned to a page already |
||
37 | $config->getComponentByType('GridFieldAddExistingAutocompleter')->setSearchList( |
||
|
|||
38 | DMSDocumentSet::get()->filter(array('PageID' => 0)) |
||
39 | ); |
||
40 | |||
41 | $fields->addFieldToTab( |
||
42 | 'Root.DocumentSets', |
||
43 | $gridField |
||
44 | ); |
||
45 | |||
46 | $fields |
||
47 | ->findOrMakeTab('Root.DocumentSets') |
||
48 | ->setTitle(_t( |
||
49 | __CLASS__ . '.DocumentSetsTabTitle', |
||
50 | 'Document Sets ({count})', |
||
51 | array('count' => $this->owner->DocumentSets()->count()) |
||
52 | )); |
||
53 | } |
||
54 | |||
55 | /** |
||
56 | * Get a list of document sets for the owner page |
||
57 | * |
||
58 | * @return ArrayList |
||
59 | */ |
||
60 | public function getDocumentSets() |
||
64 | |||
65 | /** |
||
66 | * Get a list of all documents from all document sets for the owner page |
||
67 | * |
||
68 | * @return ArrayList |
||
69 | */ |
||
70 | public function getAllDocuments() |
||
82 | |||
83 | public function onBeforeDelete() |
||
103 | |||
104 | public function onBeforePublish() |
||
114 | |||
115 | /** |
||
116 | * Returns the title of the page with the total number of documents it has associated with it across |
||
117 | * all document sets |
||
118 | * |
||
119 | * @return string |
||
120 | */ |
||
121 | public function getTitleWithNumberOfDocuments() |
||
125 | } |
||
126 |
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the interface: