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