1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @author Donatas Navidonskis <[email protected]> |
5
|
|
|
* @since 2017 |
6
|
|
|
* @class BaseSliderItem |
7
|
|
|
* |
8
|
|
|
* @property int BlockID |
9
|
|
|
* @property int SortOrder |
10
|
|
|
* @property string Title |
11
|
|
|
* @property string Content |
12
|
|
|
* |
13
|
|
|
* @method SliderBlock Block |
14
|
|
|
*/ |
15
|
|
|
class BaseSliderItem extends \DataObject { |
|
|
|
|
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @var array |
19
|
|
|
* @config |
20
|
|
|
*/ |
21
|
|
|
private static $db = [ |
|
|
|
|
22
|
|
|
'Title' => 'Varchar', |
23
|
|
|
'Content' => 'HTMLText', |
24
|
|
|
'SortOrder' => 'Int', |
25
|
|
|
]; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var array |
29
|
|
|
* @config |
30
|
|
|
*/ |
31
|
|
|
private static $has_one = [ |
|
|
|
|
32
|
|
|
'Block' => 'SliderBlock', |
33
|
|
|
]; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* The default sort expression. This will be inserted in the ORDER BY |
37
|
|
|
* clause of a SQL query if no other sort expression is provided. |
38
|
|
|
* |
39
|
|
|
* @var string |
40
|
|
|
* @config |
41
|
|
|
*/ |
42
|
|
|
private static $default_sort = 'SortOrder ASC'; |
|
|
|
|
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @return string |
46
|
|
|
*/ |
47
|
|
|
public function singular_name() { |
48
|
|
|
return _t('SliderItem.SINGULARNAME', 'Slider'); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @return string |
53
|
|
|
*/ |
54
|
|
|
public function plural_name() { |
55
|
|
|
return _t('SliderItem.PLURALNAME', 'Sliders'); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Default summary fields within localized label title's. |
60
|
|
|
* |
61
|
|
|
* @return array |
62
|
|
|
*/ |
63
|
|
|
public function summaryFields() { |
64
|
|
|
return [ |
65
|
|
|
'Title' => $this->fieldLabel('Title'), |
66
|
|
|
'SliderType' => $this->fieldLabel('SliderType'), |
67
|
|
|
]; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @return string |
72
|
|
|
*/ |
73
|
|
|
public function getSliderType() { |
74
|
|
|
return $this->singular_name(); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @return \FieldList |
79
|
|
|
*/ |
80
|
|
|
public function getCMSFields() { |
81
|
|
|
$fields = parent::getCMSFields(); |
82
|
|
|
$fields->removeByName(['SortOrder', 'Title', 'Content']); |
83
|
|
|
$fields->findOrMakeTab('Root.Media', $this->fieldLabel('Media')); |
84
|
|
|
|
85
|
|
|
$fields->addFieldsToTab('Root.Main', [ |
86
|
|
|
\TextField::create('Title', $this->fieldLabel('Title')), |
87
|
|
|
$contentField = \HtmlEditorField::create('Content', $this->fieldLabel('Content')), |
88
|
|
|
]); |
89
|
|
|
|
90
|
|
|
$contentField |
91
|
|
|
->setRows(15); |
92
|
|
|
|
93
|
|
|
$this->extend('updateCMSFields', $fields); |
94
|
|
|
|
95
|
|
|
return $fields; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @param bool $includeRelations |
100
|
|
|
* |
101
|
|
|
* @return array |
102
|
|
|
*/ |
103
|
|
|
public function fieldLabels($includeRelations = true) { |
104
|
|
|
return array_merge(parent::fieldLabels($includeRelations), [ |
105
|
|
|
'Title' => _t('SliderItem.TITLE', 'Title'), |
106
|
|
|
'Content' => _t('SliderItem.CONTENT', 'Content'), |
107
|
|
|
'Picture' => _t('SliderItem.PICTURE', 'Picture'), |
108
|
|
|
'Media' => _t('SliderItem.MEDIA', 'Media'), |
109
|
|
|
'Video' => _t('SliderItem.VIDEO', 'Video'), |
110
|
|
|
'SliderType' => _t('SliderItem.SLIDER_TYPE', 'Slider type'), |
111
|
|
|
]); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @return \HTMLText |
116
|
|
|
*/ |
117
|
|
|
public function forTemplate() { |
118
|
|
|
return $this->renderWith( |
119
|
|
|
sprintf("%s_%s", $this->Block()->ClassName, $this->ClassName) |
|
|
|
|
120
|
|
|
); |
121
|
|
|
} |
122
|
|
|
} |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.