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\Versioned\Versioned; |
17
|
|
|
use SilverStripe\View\Requirements; |
18
|
|
|
use SilverStripe\View\SSViewer; |
19
|
|
|
use SilverStripe\Core\Injector\Injector; |
20
|
|
|
use Page; |
|
|
|
|
21
|
|
|
|
22
|
|
|
class ElementalArea extends DataObject |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* @var array $db |
26
|
|
|
*/ |
27
|
|
|
private static $db = [ |
|
|
|
|
28
|
|
|
'OwnerClassName' => 'Varchar(255)', |
29
|
|
|
]; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var array $has_many |
33
|
|
|
*/ |
34
|
|
|
private static $has_many = [ |
|
|
|
|
35
|
|
|
'Elements' => BaseElement::class |
36
|
|
|
]; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @var array |
40
|
|
|
*/ |
41
|
|
|
private static $extensions = [ |
|
|
|
|
42
|
|
|
Versioned::class |
43
|
|
|
]; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @var array |
47
|
|
|
*/ |
48
|
|
|
private static $owns = [ |
|
|
|
|
49
|
|
|
'Elements' |
50
|
|
|
]; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @var array |
54
|
|
|
*/ |
55
|
|
|
private static $cascade_deletes = [ |
|
|
|
|
56
|
|
|
'Elements' |
57
|
|
|
]; |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @var array |
61
|
|
|
*/ |
62
|
|
|
private static $summary_fields = [ |
|
|
|
|
63
|
|
|
'Title' => 'Title' |
64
|
|
|
]; |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @var string |
68
|
|
|
*/ |
69
|
|
|
private static $table_name = 'ElementalArea'; |
|
|
|
|
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @return array |
73
|
|
|
*/ |
74
|
|
|
public function supportedPageTypes() |
75
|
|
|
{ |
76
|
|
|
$elementalClasses = []; |
77
|
|
|
|
78
|
|
|
foreach (ClassInfo::getValidSubClasses(SiteTree::class) as $class) { |
79
|
|
|
if (Extensible::has_extension($class, ElementalAreasExtension::class)) { |
80
|
|
|
$elementalClasses[] = $class; |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
return $elementalClasses; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @return HTMLText |
|
|
|
|
89
|
|
|
*/ |
90
|
|
|
public function forTemplate() |
91
|
|
|
{ |
92
|
|
|
return $this->renderWith(static::class); |
|
|
|
|
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* Necessary to display results in CMS site search. |
97
|
|
|
* |
98
|
|
|
* @return HTMLText |
99
|
|
|
*/ |
100
|
|
|
public function Breadcrumbs() |
101
|
|
|
{ |
102
|
|
|
$ownerClassName = $this->OwnerClassName; |
103
|
|
|
|
104
|
|
|
if ($owner = $ownerClassName::get()->filter('ElementalAreaID', $this->ID)->first()) { |
105
|
|
|
return DBField::create_field('HTMLText', sprintf( |
|
|
|
|
106
|
|
|
'<a href="%s">%s</a>', |
107
|
|
|
$owner->CMSEditLink(), |
108
|
|
|
$owner->Title |
109
|
|
|
)); |
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* Used in template instead of {@link Elements()} to wrap each element in |
115
|
|
|
* its' controller, making it easier to access and process form logic and |
116
|
|
|
* actions stored in {@link ElementController}. |
117
|
|
|
* |
118
|
|
|
* @return ArrayList |
119
|
|
|
*/ |
120
|
|
|
public function ElementControllers() |
121
|
|
|
{ |
122
|
|
|
$controllers = new ArrayList(); |
123
|
|
|
$items = $this->Elements(); |
|
|
|
|
124
|
|
|
|
125
|
|
|
if (!is_null($items)) { |
126
|
|
|
foreach ($items as $element) { |
127
|
|
|
$controller = $element->getController(); |
128
|
|
|
$controllers->push($controller); |
129
|
|
|
} |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
return $controllers; |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
public function getOwnerPage() |
136
|
|
|
{ |
137
|
|
|
if ($this->OwnerClassName) { |
138
|
|
|
$class = $this->OwnerClassName; |
139
|
|
|
$elementalAreaRelations = Injector::inst()->get($class)->getElementalRelations(); |
140
|
|
|
|
141
|
|
|
foreach ($elementalAreaRelations as $eaRelationship) { |
142
|
|
|
$areaID = $eaRelationship . 'ID'; |
143
|
|
|
|
144
|
|
|
$page = $class::get()->filter($areaID, $this->ID); |
145
|
|
|
|
146
|
|
|
if ($page && $page->exists()) { |
147
|
|
|
return $page->first(); |
148
|
|
|
} |
149
|
|
|
} |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
$originalMode = Versioned::get_stage(); |
153
|
|
|
|
154
|
|
|
if (!$originalMode) { |
155
|
|
|
$originalMode = Versioned::DRAFT; |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
Versioned::set_stage(Versioned::DRAFT); |
159
|
|
|
|
160
|
|
|
foreach ($this->supportedPageTypes() as $class) { |
161
|
|
|
$elementalAreaRelations = Injector::inst()->get($class)->getElementalRelations(); |
162
|
|
|
|
163
|
|
|
foreach ($elementalAreaRelations as $eaRelationship) { |
164
|
|
|
$areaID = $eaRelationship . 'ID'; |
165
|
|
|
$page = $class::get()->filter($areaID, $this->ID); |
166
|
|
|
|
167
|
|
|
if ($page && $page->exists()) { |
168
|
|
|
Versioned::set_stage($originalMode); |
169
|
|
|
$this->OwnerClassName = $class; |
|
|
|
|
170
|
|
|
$this->write(); |
171
|
|
|
|
172
|
|
|
return $page->first(); |
173
|
|
|
} |
174
|
|
|
} |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
Versioned::set_stage($originalMode); |
178
|
|
|
|
179
|
|
|
return false; |
180
|
|
|
} |
181
|
|
|
} |
182
|
|
|
|
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