1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Class PageSectionObject |
5
|
|
|
* |
6
|
|
|
* @property string $Name |
7
|
|
|
* @property string $Title |
8
|
|
|
* @property HTMLText $Content |
9
|
|
|
* @property int $SortOrder |
10
|
|
|
* @property int $ImageID |
11
|
|
|
* @property int $PageSectionBlockID |
12
|
|
|
*/ |
13
|
|
|
class PageSectionObject extends DataObject |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* @return string |
17
|
|
|
*/ |
18
|
|
|
private static $singular_name = 'Page Section'; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @return string |
22
|
|
|
*/ |
23
|
|
|
private static $plural_name = 'Page Sections'; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var array |
27
|
|
|
*/ |
28
|
|
|
private static $db = array( |
29
|
|
|
'Name' => 'Varchar(255)', |
30
|
|
|
'Title' => 'Varchar(255)', |
31
|
|
|
'Content' => 'HTMLText', |
32
|
|
|
'SortOrder' => 'Int', |
33
|
|
|
); |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var array |
37
|
|
|
*/ |
38
|
|
|
private static $has_one = array( |
39
|
|
|
'Image' => 'Image', |
40
|
|
|
'PageSectionBlock' => 'PageSectionBlock', |
41
|
|
|
'BlockLink' => 'Link', |
42
|
|
|
); |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @var string |
46
|
|
|
*/ |
47
|
|
|
private static $default_sort = 'Name ASC'; |
|
|
|
|
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @var array |
51
|
|
|
*/ |
52
|
|
|
private static $summary_fields = array( |
53
|
|
|
'Image.CMSThumbnail' => 'Image', |
54
|
|
|
'Name' => 'Name', |
55
|
|
|
'Title' => 'Title', |
56
|
|
|
); |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @var array |
60
|
|
|
*/ |
61
|
|
|
private static $searchable_fields = array( |
62
|
|
|
'Name' => 'Name', |
63
|
|
|
'Title' => 'Title', |
64
|
|
|
); |
65
|
|
|
|
66
|
|
|
private static $extensions = [ |
67
|
|
|
'VersionedDataObject' |
68
|
|
|
]; |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @return FieldList |
72
|
|
|
*/ |
73
|
1 |
|
public function getCMSFields() |
74
|
|
|
{ |
75
|
1 |
|
$this->beforeUpdateCMSFields(function ($fields) { |
76
|
1 |
|
$fields->addFieldToTab( |
77
|
1 |
|
'Root.Main', |
78
|
1 |
|
LinkField::create('BlockLinkID', 'Link'), |
79
|
|
|
'Content' |
80
|
1 |
|
); |
81
|
1 |
|
}); |
82
|
|
|
|
83
|
1 |
|
$fields = parent::getCMSFields(); |
84
|
|
|
|
85
|
1 |
|
$fields->removeByName(array( |
86
|
1 |
|
'PageSectionBlockID', |
87
|
1 |
|
'SortOrder', |
88
|
1 |
|
)); |
89
|
|
|
|
90
|
1 |
|
$fields->dataFieldByName('Name')->setDescription('For internal reference only'); |
91
|
|
|
|
92
|
1 |
|
$image = $fields->dataFieldByName('Image'); |
93
|
1 |
|
$image->setFolderName('Uploads/PageSections'); |
94
|
1 |
|
$fields->insertBefore($image, 'Content'); |
|
|
|
|
95
|
|
|
|
96
|
1 |
|
return $fields; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @return ValidationResult |
101
|
|
|
*/ |
102
|
1 |
|
public function validate() |
103
|
|
|
{ |
104
|
1 |
|
$result = parent::validate(); |
105
|
|
|
|
106
|
1 |
|
if (!$this->Name) { |
107
|
1 |
|
$result->error('Name is requied before you can save'); |
108
|
1 |
|
} |
109
|
|
|
|
110
|
1 |
|
return $result; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* Set permissions, allow all users to access by default. |
115
|
|
|
* Override in descendant classes, or use PermissionProvider. |
116
|
|
|
*/ |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* @param null $member |
120
|
|
|
* |
121
|
|
|
* @return bool |
122
|
|
|
*/ |
123
|
1 |
|
public function canCreate($member = null) |
124
|
|
|
{ |
125
|
1 |
|
return true; |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* @param null $member |
130
|
|
|
* |
131
|
|
|
* @return bool |
132
|
|
|
*/ |
133
|
1 |
|
public function canView($member = null) |
134
|
|
|
{ |
135
|
1 |
|
return true; |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* @param null $member |
140
|
|
|
* |
141
|
|
|
* @return bool |
142
|
|
|
*/ |
143
|
1 |
|
public function canEdit($member = null) |
144
|
|
|
{ |
145
|
1 |
|
return true; |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* @param null $member |
150
|
|
|
* |
151
|
|
|
* @return bool |
152
|
|
|
*/ |
153
|
1 |
|
public function canDelete($member = null) |
154
|
|
|
{ |
155
|
1 |
|
return true; |
156
|
|
|
} |
157
|
|
|
} |
This check marks private properties in classes that are never used. Those properties can be removed.