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