1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @package elemental |
5
|
|
|
*/ |
6
|
|
|
class ElementalWidgetExtension extends DataExtension |
|
|
|
|
7
|
|
|
{ |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* @param array $fields |
11
|
|
|
*/ |
12
|
|
|
public function updateSummaryFields(&$fields) |
13
|
|
|
{ |
14
|
|
|
unset($fields['CMSPublishedState']); |
15
|
|
|
} |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Basic permissions, defaults to page perms where possible |
19
|
|
|
*/ |
20
|
|
View Code Duplication |
public function canView($member = null) |
|
|
|
|
21
|
|
|
{ |
22
|
|
|
if ($page = $this->owner->getPage()) { |
23
|
|
|
return $page->canView($member); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
if(Director::is_cli()) return true; |
27
|
|
|
|
28
|
|
|
return (Permission::check('CMS_ACCESS_CMSMain', 'any', $member)) ? true : null; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Basic permissions, defaults to page perms where possible |
33
|
|
|
*/ |
34
|
|
View Code Duplication |
public function canEdit($member = null) |
|
|
|
|
35
|
|
|
{ |
36
|
|
|
if ($page = $this->owner->getPage()) { |
37
|
|
|
return $page->canEdit($member); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
if(Director::is_cli()) return true; |
41
|
|
|
|
42
|
|
|
return (Permission::check('CMS_ACCESS_CMSMain', 'any', $member)) ? true : null; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Basic permissions, defaults to page perms where possible |
47
|
|
|
* Uses archive not delete so that current stage is respected |
48
|
|
|
* i.e if a widget is not published, then it can be deleted by someone who |
49
|
|
|
* doesn't have publishing permissions |
50
|
|
|
*/ |
51
|
|
View Code Duplication |
public function canDelete($member = null) |
|
|
|
|
52
|
|
|
{ |
53
|
|
|
if ($page = $this->owner->getPage()) { |
54
|
|
|
return $page->canArchive($member); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
if(Director::is_cli()) return true; |
58
|
|
|
|
59
|
|
|
return (Permission::check('CMS_ACCESS_CMSMain', 'any', $member)) ? true : null; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Basic permissions, defaults to page perms where possible |
64
|
|
|
*/ |
65
|
|
|
public function canCreate($member = null) |
66
|
|
|
{ |
67
|
|
|
if(Director::is_cli()) return true; |
68
|
|
|
|
69
|
|
|
return (Permission::check('CMS_ACCESS_CMSMain', 'any', $member)) ? true : null; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Handles unpublishing as VersionedDataObjects doesn't |
74
|
|
|
* Modelled on SiteTree::doUnpublish |
75
|
|
|
* Has to be applied here, rather than BaseElement so that goes against Widget |
76
|
|
|
*/ |
77
|
|
|
public function doUnpublish() { |
78
|
|
|
if(!$this->owner->ID) return false; |
79
|
|
|
|
80
|
|
|
$this->owner->extend('onBeforeUnpublish'); |
81
|
|
|
|
82
|
|
|
$origStage = Versioned::get_reading_mode(); |
83
|
|
|
Versioned::set_reading_mode('Stage.Live'); |
84
|
|
|
|
85
|
|
|
// This way our ID won't be unset |
86
|
|
|
$clone = clone $this->owner; |
87
|
|
|
$clone->delete(); |
88
|
|
|
|
89
|
|
|
Versioned::set_reading_mode($origStage); |
90
|
|
|
|
91
|
|
|
$virtualLinkedElements = $this->owner->getPublishedVirtualLinkedElements(); |
92
|
|
|
if ($virtualLinkedElements) foreach($virtualLinkedElements as $vle) $vle->doUnpublish(); |
93
|
|
|
|
94
|
|
|
$this->owner->extend('onAfterUnpublish'); |
95
|
|
|
|
96
|
|
|
return true; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
} |
100
|
|
|
|
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.