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
|
|
|
'Link' => 'Link', |
30
|
|
|
); |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var string |
34
|
|
|
*/ |
35
|
|
|
private static $default_sort = 'Name ASC'; |
|
|
|
|
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @var array |
39
|
|
|
*/ |
40
|
|
|
private static $summary_fields = array( |
41
|
|
|
'Image.CMSThumbnail' => 'Image', |
42
|
|
|
'Name' => 'Name', |
43
|
|
|
'Title' => 'Title', |
44
|
|
|
); |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @var array |
48
|
|
|
*/ |
49
|
|
|
private static $searchable_fields = array( |
50
|
|
|
'Name' => 'Name', |
51
|
|
|
'Title' => 'Title', |
52
|
|
|
); |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @var array |
56
|
|
|
*/ |
57
|
|
|
private static $belongs_many_many = array( |
58
|
|
|
'PromoBlocks' => 'PromoBlock' |
59
|
|
|
); |
60
|
|
|
|
61
|
1 |
|
public function getCMSFields() |
62
|
|
|
{ |
63
|
1 |
|
$this->beforeUpdateCMSFields(function ($fields) { |
64
|
1 |
|
$fields->addFieldToTab( |
65
|
1 |
|
'Root.Main', |
66
|
1 |
|
LinkField::create('LinkID', 'Link'), |
67
|
|
|
'Content' |
68
|
1 |
|
); |
69
|
1 |
|
}); |
70
|
|
|
|
71
|
1 |
|
$fields = parent::getCMSFields(); |
72
|
|
|
|
73
|
1 |
|
$fields->removeByName(array( |
74
|
1 |
|
'PromoBlocks', |
75
|
1 |
|
)); |
76
|
|
|
|
77
|
1 |
|
$fields->dataFieldByName('Name')->setDescription('For internal reference only'); |
78
|
|
|
|
79
|
1 |
|
$image = $fields->dataFieldByName('Image'); |
80
|
1 |
|
$image->setFolderName('Uploads/Promos'); |
81
|
1 |
|
$fields->insertBefore($image, 'Content'); |
|
|
|
|
82
|
|
|
|
83
|
1 |
|
$config = GridFieldConfig_RecordViewer::create(); |
84
|
1 |
|
$fields->addFieldToTab('Root.Blocks', GridField::create('PromoBlocks', 'Blocks', $this->PromoBlocks(), $config)); |
|
|
|
|
85
|
|
|
|
86
|
1 |
|
return $fields; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @return ValidationResult |
91
|
|
|
*/ |
92
|
|
|
public function validate() |
93
|
|
|
{ |
94
|
|
|
$result = parent::validate(); |
95
|
|
|
|
96
|
|
|
if (!$this->Name) { |
|
|
|
|
97
|
|
|
$result->error('Name is requied before you can save'); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
return $result; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* Set permissions, allow all users to access by default. |
105
|
|
|
* Override in descendant classes, or use PermissionProvider. |
106
|
|
|
*/ |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* @param null $member |
110
|
|
|
* |
111
|
|
|
* @return bool |
112
|
|
|
*/ |
113
|
|
|
public function canCreate($member = null) |
114
|
|
|
{ |
115
|
|
|
return true; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* @param null $member |
120
|
|
|
* |
121
|
|
|
* @return bool |
122
|
|
|
*/ |
123
|
|
|
public function canView($member = null) |
124
|
|
|
{ |
125
|
|
|
return true; |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* @param null $member |
130
|
|
|
* |
131
|
|
|
* @return bool |
132
|
|
|
*/ |
133
|
|
|
public function canEdit($member = null) |
134
|
|
|
{ |
135
|
|
|
return true; |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* @param null $member |
140
|
|
|
* |
141
|
|
|
* @return bool |
142
|
|
|
*/ |
143
|
|
|
public function canDelete($member = null) |
144
|
|
|
{ |
145
|
|
|
return true; |
146
|
|
|
} |
147
|
|
|
} |
This check marks private properties in classes that are never used. Those properties can be removed.