1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
class PromoObject extends DataObject |
4
|
|
|
{ |
5
|
|
|
/** |
6
|
|
|
* @return string |
7
|
|
|
*/ |
8
|
|
|
private static $singular_name = 'Promo'; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* @return string |
12
|
|
|
*/ |
13
|
|
|
private static $plural_name = 'Promos'; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @var array |
17
|
|
|
*/ |
18
|
|
|
private static $db = array( |
19
|
|
|
'Name' => 'Varchar(255)', |
20
|
|
|
'Title' => 'Varchar(255)', |
21
|
|
|
'Content' => 'HTMLText', |
22
|
|
|
); |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var array |
26
|
|
|
*/ |
27
|
|
|
private static $has_one = array( |
28
|
|
|
'Image' => 'Image', |
29
|
|
|
'BlockLink' => 'Link', |
30
|
|
|
); |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var array |
34
|
|
|
*/ |
35
|
|
|
private static $belongs_many_many = array( |
36
|
|
|
'PromoBlocks' => 'PromoBlock' |
37
|
|
|
); |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var string |
41
|
|
|
*/ |
42
|
|
|
private static $default_sort = 'Name ASC'; |
|
|
|
|
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @var array |
46
|
|
|
*/ |
47
|
|
|
private static $summary_fields = array( |
48
|
|
|
'Image.CMSThumbnail' => 'Image', |
49
|
|
|
'Name' => 'Name', |
50
|
|
|
'Title' => 'Title', |
51
|
|
|
); |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @var array |
55
|
|
|
*/ |
56
|
|
|
private static $searchable_fields = array( |
57
|
|
|
'Name' => 'Name', |
58
|
|
|
'Title' => 'Title', |
59
|
|
|
); |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @var array |
63
|
|
|
*/ |
64
|
|
|
private static $extensions = [ |
65
|
|
|
'VersionedDataObject', |
66
|
|
|
]; |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @return FieldList |
70
|
|
|
*/ |
71
|
1 |
|
public function getCMSFields() |
72
|
|
|
{ |
73
|
1 |
|
$this->beforeUpdateCMSFields(function ($fields) { |
74
|
1 |
|
$fields->addFieldToTab( |
75
|
1 |
|
'Root.Main', |
76
|
1 |
|
LinkField::create('BlockLinkID', 'Link'), |
77
|
|
|
'Content' |
78
|
1 |
|
); |
79
|
1 |
|
}); |
80
|
|
|
|
81
|
1 |
|
$fields = parent::getCMSFields(); |
82
|
|
|
|
83
|
1 |
|
$fields->removeByName(array( |
84
|
1 |
|
'PromoBlocks', |
85
|
1 |
|
)); |
86
|
|
|
|
87
|
1 |
|
$fields->dataFieldByName('Name')->setDescription('For internal reference only'); |
88
|
|
|
|
89
|
1 |
|
$image = $fields->dataFieldByName('Image'); |
90
|
1 |
|
$image->setFolderName('Uploads/Promos'); |
91
|
1 |
|
$fields->insertBefore($image, 'Content'); |
|
|
|
|
92
|
|
|
|
93
|
1 |
|
$config = GridFieldConfig_RecordViewer::create(); |
94
|
1 |
|
$fields->addFieldToTab('Root.Blocks', GridField::create('PromoBlocks', 'Blocks', $this->PromoBlocks(), $config)); |
|
|
|
|
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.