1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use \Heyday\VersionedDataObjects\VersionedDataObject; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* @package elemental |
7
|
|
|
*/ |
8
|
|
|
class BaseElementExtension extends VersionedDataObject |
|
|
|
|
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* {@inheritDoc} |
12
|
|
|
*/ |
13
|
|
|
public function canView($member = null) |
14
|
|
|
{ |
15
|
|
|
return (Permission::check('CMS_ACCESS_CMSMain', 'any', $member)) ? true : null; |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* {@inheritDoc} |
20
|
|
|
*/ |
21
|
|
|
public function canEdit($member = null) |
22
|
|
|
{ |
23
|
|
|
return (Permission::check('CMS_ACCESS_CMSMain', 'any', $member)) ? true : null; |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* {@inheritDoc} |
28
|
|
|
*/ |
29
|
|
|
public function canDelete($member = null) |
30
|
|
|
{ |
31
|
|
|
return (Permission::check('CMS_ACCESS_CMSMain', 'any', $member)) ? true : null; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* {@inheritDoc} |
36
|
|
|
*/ |
37
|
|
|
public function canCreate($member = null) |
38
|
|
|
{ |
39
|
|
|
return (Permission::check('CMS_ACCESS_CMSMain', 'any', $member)) ? true : null; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Handles unpublishing as VersionedDataObjects doesn't |
44
|
|
|
* Modelled on SiteTree::doUnpublish |
45
|
|
|
* |
46
|
|
|
*/ |
47
|
|
|
public function doUnpublish() { |
48
|
|
|
if(!$this->owner->ID) return false; |
49
|
|
|
|
50
|
|
|
$this->owner->extend('onBeforeUnpublish'); |
51
|
|
|
|
52
|
|
|
$origStage = Versioned::get_reading_mode(); |
53
|
|
|
Versioned::set_reading_mode('Stage.Live'); |
54
|
|
|
|
55
|
|
|
// This way our ID won't be unset |
56
|
|
|
$clone = clone $this->owner; |
57
|
|
|
$clone->delete(); |
58
|
|
|
|
59
|
|
|
Versioned::set_reading_mode($origStage); |
60
|
|
|
|
61
|
|
|
$virtualLinkedElements = $this->owner->getPublishedVirtualLinkedElements(); |
62
|
|
|
if ($virtualLinkedElements) foreach($virtualLinkedElements as $vle) $vle->doUnpublish(); |
63
|
|
|
|
64
|
|
|
$this->owner->extend('onAfterUnpublish'); |
65
|
|
|
|
66
|
|
|
return true; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
} |
70
|
|
|
|
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.