1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace DNADesign\Elemental\Models; |
4
|
|
|
|
5
|
|
|
use DNADesign\Elemental\Extensions\ElementalAreasExtension; |
6
|
|
|
use DNADesign\Elemental\Models\BaseElement; |
7
|
|
|
|
8
|
|
|
use SilverStripe\CMS\Model\SiteTree; |
9
|
|
|
use SilverStripe\Core\ClassInfo; |
10
|
|
|
use SilverStripe\Core\Convert; |
11
|
|
|
use SilverStripe\Core\Extensible; |
12
|
|
|
use SilverStripe\ORM\ArrayList; |
13
|
|
|
use SilverStripe\ORM\DataObject; |
14
|
|
|
use SilverStripe\ORM\HasManyList; |
15
|
|
|
use SilverStripe\ORM\UnsavedRelationList; |
16
|
|
|
use SilverStripe\Security\Permission; |
17
|
|
|
use SilverStripe\Versioned\Versioned; |
18
|
|
|
use SilverStripe\View\Requirements; |
19
|
|
|
use SilverStripe\View\SSViewer; |
20
|
|
|
use SilverStripe\Core\Injector\Injector; |
21
|
|
|
use Page; |
|
|
|
|
22
|
|
|
|
23
|
|
|
class ElementalArea extends DataObject |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* @var array $db |
27
|
|
|
*/ |
28
|
|
|
private static $db = [ |
|
|
|
|
29
|
|
|
'OwnerClassName' => 'Varchar(255)', |
30
|
|
|
]; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var array $has_many |
34
|
|
|
*/ |
35
|
|
|
private static $has_many = [ |
|
|
|
|
36
|
|
|
'Elements' => BaseElement::class |
37
|
|
|
]; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var array |
41
|
|
|
*/ |
42
|
|
|
private static $extensions = [ |
|
|
|
|
43
|
|
|
Versioned::class |
44
|
|
|
]; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @var array |
48
|
|
|
*/ |
49
|
|
|
private static $owns = [ |
|
|
|
|
50
|
|
|
'Elements' |
51
|
|
|
]; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @var array |
55
|
|
|
*/ |
56
|
|
|
private static $cascade_deletes = [ |
|
|
|
|
57
|
|
|
'Elements' |
58
|
|
|
]; |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @var array |
62
|
|
|
*/ |
63
|
|
|
private static $summary_fields = [ |
|
|
|
|
64
|
|
|
'Title' => 'Title' |
65
|
|
|
]; |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @var string |
69
|
|
|
*/ |
70
|
|
|
private static $table_name = 'ElementalArea'; |
|
|
|
|
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @return array |
74
|
|
|
*/ |
75
|
|
|
public function supportedPageTypes() |
76
|
|
|
{ |
77
|
|
|
$elementalClasses = []; |
78
|
|
|
|
79
|
|
|
foreach (ClassInfo::getValidSubClasses(SiteTree::class) as $class) { |
80
|
|
|
if (Extensible::has_extension($class, ElementalAreasExtension::class)) { |
81
|
|
|
$elementalClasses[] = $class; |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
return $elementalClasses; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @return HTMLText |
|
|
|
|
90
|
|
|
*/ |
91
|
|
|
public function forTemplate() |
92
|
|
|
{ |
93
|
|
|
return $this->renderWith(static::class); |
|
|
|
|
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Necessary to display results in CMS site search. |
98
|
|
|
* |
99
|
|
|
* @return HTMLText |
100
|
|
|
*/ |
101
|
|
|
public function Breadcrumbs() |
102
|
|
|
{ |
103
|
|
|
$ownerClassName = $this->OwnerClassName; |
104
|
|
|
|
105
|
|
|
if ($owner = $ownerClassName::get()->filter('ElementalAreaID', $this->ID)->first()) { |
106
|
|
|
return DBField::create_field('HTMLText', sprintf( |
|
|
|
|
107
|
|
|
'<a href="%s">%s</a>', |
108
|
|
|
$owner->CMSEditLink(), |
109
|
|
|
$owner->Title |
110
|
|
|
)); |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* Used in template instead of {@link Elements()} to wrap each element in |
116
|
|
|
* its' controller, making it easier to access and process form logic and |
117
|
|
|
* actions stored in {@link ElementController}. |
118
|
|
|
* |
119
|
|
|
* @return ArrayList |
120
|
|
|
*/ |
121
|
|
|
public function ElementControllers() |
122
|
|
|
{ |
123
|
|
|
$controllers = new ArrayList(); |
124
|
|
|
$items = $this->Elements(); |
|
|
|
|
125
|
|
|
|
126
|
|
|
if (!is_null($items)) { |
127
|
|
|
foreach ($items as $element) { |
128
|
|
|
$controller = $element->getController(); |
129
|
|
|
$controllers->push($controller); |
130
|
|
|
} |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
return $controllers; |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
public function getOwnerPage() |
137
|
|
|
{ |
138
|
|
|
if ($this->OwnerClassName) { |
139
|
|
|
$class = $this->OwnerClassName; |
140
|
|
|
$instance = Injector::inst()->get($class); |
141
|
|
|
if (!ClassInfo::hasMethod($instance, 'getElementalRelations')) { |
142
|
|
|
return; |
143
|
|
|
} |
144
|
|
|
$elementalAreaRelations = $instance->getElementalRelations(); |
145
|
|
|
|
146
|
|
|
foreach ($elementalAreaRelations as $eaRelationship) { |
147
|
|
|
$areaID = $eaRelationship . 'ID'; |
148
|
|
|
|
149
|
|
|
$page = Versioned::get_by_stage($class, Versioned::get_stage())->filter($areaID, $this->ID); |
150
|
|
|
|
151
|
|
|
if ($page && $page->exists()) { |
152
|
|
|
return $page->first(); |
153
|
|
|
} |
154
|
|
|
} |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
foreach ($this->supportedPageTypes() as $class) { |
158
|
|
|
$instance = Injector::inst()->get($class); |
159
|
|
|
if (!ClassInfo::hasMethod($instance, 'getElementalRelations')) { |
160
|
|
|
return; |
161
|
|
|
} |
162
|
|
|
$elementalAreaRelations = $instance->getElementalRelations(); |
163
|
|
|
|
164
|
|
|
foreach ($elementalAreaRelations as $eaRelationship) { |
165
|
|
|
$areaID = $eaRelationship . 'ID'; |
166
|
|
|
$page = Versioned::get_by_stage($class, Versioned::DRAFT)->filter($areaID, $this->ID); |
167
|
|
|
|
168
|
|
|
if ($page && $page->exists()) { |
169
|
|
|
$this->OwnerClassName = $class; |
|
|
|
|
170
|
|
|
$this->write(); |
171
|
|
|
|
172
|
|
|
return $page->first(); |
173
|
|
|
} |
174
|
|
|
} |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
return false; |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
public function canEdit($member = null) |
181
|
|
|
{ |
182
|
|
|
if (Permission::check('ADMIN')) { |
183
|
|
|
return true; |
184
|
|
|
} |
185
|
|
|
return $this->getOwnerPage()->canEdit($member); |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
public function canView($member = null) |
189
|
|
|
{ |
190
|
|
|
if (Permission::check('ADMIN')) { |
191
|
|
|
return true; |
192
|
|
|
} |
193
|
|
|
return $this->getOwnerPage()->canView($member); |
194
|
|
|
} |
195
|
|
|
} |
196
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths