1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Dynamic\DynamicBlocks\Model; |
4
|
|
|
|
5
|
|
|
use Dynamic\DynamicBlocks\Block\PageSectionBlock; |
6
|
|
|
use SilverStripe\Assets\Image; |
7
|
|
|
use SilverStripe\ORM\DataObject; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Class PageSectionObject |
11
|
|
|
* |
12
|
|
|
* @property string $Name |
13
|
|
|
* @property string $Title |
14
|
|
|
* @property HTMLText $Content |
15
|
|
|
* @property int $SortOrder |
16
|
|
|
* @property int $ImageID |
17
|
|
|
* @property int $PageSectionBlockID |
18
|
|
|
*/ |
19
|
|
|
class PageSectionObject extends DataObject |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* @return string |
23
|
|
|
*/ |
24
|
|
|
private static $singular_name = 'Page Section'; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @return string |
28
|
|
|
*/ |
29
|
|
|
private static $plural_name = 'Page Sections'; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var array |
33
|
|
|
*/ |
34
|
|
|
private static $db = array( |
35
|
|
|
'Name' => 'Varchar(255)', |
36
|
|
|
'Title' => 'Varchar(255)', |
37
|
|
|
'Content' => 'HTMLText', |
38
|
|
|
'SortOrder' => 'Int', |
39
|
|
|
); |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @var array |
43
|
|
|
*/ |
44
|
|
|
private static $has_one = array( |
45
|
|
|
'Image' => Image::class, |
46
|
|
|
'PageSectionBlock' => PageSectionBlock::class, |
47
|
|
|
//'BlockLink' => 'Link', // todo readd once Linkable is SS4 compatable |
|
|
|
|
48
|
|
|
); |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @var string |
52
|
|
|
*/ |
53
|
|
|
private static $default_sort = 'Name ASC'; |
|
|
|
|
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @var array |
57
|
|
|
*/ |
58
|
|
|
private static $summary_fields = array( |
59
|
|
|
'Image.CMSThumbnail' => 'Image', |
60
|
|
|
'Name' => 'Name', |
61
|
|
|
'Title' => 'Title', |
62
|
|
|
); |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @var array |
66
|
|
|
*/ |
67
|
|
|
private static $searchable_fields = array( |
68
|
|
|
'Name' => 'Name', |
69
|
|
|
'Title' => 'Title', |
70
|
|
|
); |
71
|
|
|
|
72
|
|
|
/** |
73
|
1 |
|
* @return FieldList |
74
|
|
|
*/ |
75
|
1 |
|
public function getCMSFields() |
76
|
1 |
|
{ |
77
|
1 |
|
$this->beforeUpdateCMSFields(function ($fields) { |
|
|
|
|
78
|
1 |
|
|
79
|
|
|
/* |
|
|
|
|
80
|
1 |
|
$fields->addFieldToTab( |
81
|
1 |
|
'Root.Main', |
82
|
|
|
LinkField::create('BlockLinkID', 'Link'), |
83
|
1 |
|
'Content' |
84
|
|
|
); |
85
|
1 |
|
*/ |
86
|
1 |
|
}); |
87
|
1 |
|
|
88
|
1 |
|
$fields = parent::getCMSFields(); |
89
|
|
|
|
90
|
1 |
|
$fields->removeByName(array( |
91
|
|
|
'PageSectionBlockID', |
92
|
1 |
|
'SortOrder', |
93
|
1 |
|
)); |
94
|
1 |
|
|
95
|
|
|
$fields->dataFieldByName('Name')->setDescription('For internal reference only'); |
96
|
1 |
|
|
97
|
|
|
$image = $fields->dataFieldByName('Image'); |
98
|
|
|
$image->setFolderName('Uploads/PageSections'); |
99
|
|
|
$fields->insertBefore($image, 'Content'); |
|
|
|
|
100
|
|
|
|
101
|
|
|
return $fields; |
102
|
1 |
|
} |
103
|
|
|
|
104
|
1 |
|
/** |
105
|
|
|
* @return ValidationResult |
106
|
1 |
|
*/ |
107
|
1 |
|
public function validate() |
108
|
1 |
|
{ |
109
|
|
|
$result = parent::validate(); |
110
|
1 |
|
|
111
|
|
|
if (!$this->Name) { |
112
|
|
|
$result->addError('Name is requied before you can save'); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
return $result; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* Set permissions, allow all users to access by default. |
120
|
|
|
* Override in descendant classes, or use PermissionProvider. |
121
|
|
|
*/ |
122
|
|
|
|
123
|
1 |
|
/** |
124
|
|
|
* @param null $member |
125
|
1 |
|
* |
126
|
|
|
* @return bool |
127
|
|
|
*/ |
128
|
|
|
public function canCreate($member = null, $context = []) |
129
|
|
|
{ |
130
|
|
|
return true; |
131
|
|
|
} |
132
|
|
|
|
133
|
1 |
|
/** |
134
|
|
|
* @param null $member |
135
|
1 |
|
* |
136
|
|
|
* @return bool |
137
|
|
|
*/ |
138
|
|
|
public function canView($member = null, $context = []) |
|
|
|
|
139
|
|
|
{ |
140
|
|
|
return true; |
141
|
|
|
} |
142
|
|
|
|
143
|
1 |
|
/** |
144
|
|
|
* @param null $member |
145
|
1 |
|
* |
146
|
|
|
* @return bool |
147
|
|
|
*/ |
148
|
|
|
public function canEdit($member = null, $context = []) |
|
|
|
|
149
|
|
|
{ |
150
|
|
|
return true; |
151
|
|
|
} |
152
|
|
|
|
153
|
1 |
|
/** |
154
|
|
|
* @param null $member |
155
|
1 |
|
* |
156
|
|
|
* @return bool |
157
|
|
|
*/ |
158
|
|
|
public function canDelete($member = null, $context = []) |
|
|
|
|
159
|
|
|
{ |
160
|
|
|
return true; |
161
|
|
|
} |
162
|
|
|
} |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.