1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
*@author nicolaas [at] sunnysideup.co.nz |
5
|
|
|
* |
6
|
|
|
* |
7
|
|
|
**/ |
8
|
|
|
|
9
|
|
|
class CallToAction extends DataObject |
|
|
|
|
10
|
|
|
{ |
11
|
|
|
private static $db = [ |
|
|
|
|
12
|
|
|
'Title' => 'Varchar(100)', |
13
|
|
|
'Text' => 'Varchar(255)', |
14
|
|
|
'FontColour' => 'enum("white,black", "white")', |
15
|
|
|
'ImageFocusPoint' => 'enum("Centre,N,NW,W,SW,S,SE,E,NE", "Centre")', |
16
|
|
|
'CallToAction' => 'Varchar(50)', |
17
|
|
|
'VideoBackground' => 'Varchar(255)' |
18
|
|
|
]; |
19
|
|
|
|
20
|
|
|
private static $has_one = [ |
|
|
|
|
21
|
|
|
'Image' => 'Image', |
22
|
|
|
'Link' => 'SiteTree' |
23
|
|
|
]; |
24
|
|
|
|
25
|
|
|
private static $summary_fields = [ |
|
|
|
|
26
|
|
|
'Title' => 'Title', |
27
|
|
|
'Text' => 'Text', |
28
|
|
|
'Link.Title' => 'Link', |
29
|
|
|
'Image.CMSThumbNail' => 'Image' |
30
|
|
|
]; |
31
|
|
|
|
32
|
|
|
private static $has_many = [ |
|
|
|
|
33
|
|
|
'Pages' => 'Page' |
34
|
|
|
]; |
35
|
|
|
|
36
|
|
|
private static $default_sort = [ |
|
|
|
|
37
|
|
|
'Title' => 'ASC' |
38
|
|
|
]; |
39
|
|
|
|
40
|
|
|
private static $singular_name = 'Call To Action'; |
|
|
|
|
41
|
|
|
|
42
|
|
|
private static $plural_name = 'Calls To Action'; |
|
|
|
|
43
|
|
|
|
44
|
|
|
private static $field_labels = [ |
|
|
|
|
45
|
|
|
'Title' => 'Title', |
46
|
|
|
'Text' => 'Text', |
47
|
|
|
'FontColour' => 'Text Colour', |
48
|
|
|
'ImageFocusPoint' => 'Focus Point', |
49
|
|
|
'CallToAction' => 'Call to Action', |
50
|
|
|
'Image' => 'Image', |
51
|
|
|
'Link' => 'Link' |
52
|
|
|
]; |
53
|
|
|
|
54
|
|
|
private static $colour_font_options = [ |
|
|
|
|
55
|
|
|
'white' => 'white', |
56
|
|
|
'black' => 'black' |
57
|
|
|
]; |
58
|
|
|
|
59
|
|
|
private static $field_labels_right = [ |
|
|
|
|
60
|
|
|
'Title' => 'A few words.', |
61
|
|
|
'Text' => 'A short sentence showing as the main text on the image.', |
62
|
|
|
'FontColour' => 'Text colour', |
63
|
|
|
'ImageFocusPoint' => 'What part of the image should be visible no matter what?', |
64
|
|
|
'Image' => 'Please ensure it is at least 2800px wide, but preferably a highly compressed image of 4800px wide', |
65
|
|
|
'CallToAction' => 'The text on the button - e.g. Sign Up Now (Optional)', |
66
|
|
|
'VideoBackground' => 'A link to a video anywhere on the internet. This takes priority over the image below.', |
67
|
|
|
'Link' => 'Optional link on button, if left blank users will simply scroll down.' |
68
|
|
|
]; |
69
|
|
|
|
70
|
|
|
public function getCMSFields() |
71
|
|
|
{ |
72
|
|
|
$fields = parent::getCMSFields(); |
73
|
|
|
$fieldLabels = $this->FieldLabels(); |
74
|
|
|
$fieldLabelsRight = Config::inst()->get('CallToAction', 'field_labels_right'); |
75
|
|
|
$fields->addFieldsToTab( |
76
|
|
|
'Root.Main', |
77
|
|
|
[ |
78
|
|
|
UploadField::create( |
79
|
|
|
'Image', |
80
|
|
|
$fieldLabels['Image'] |
81
|
|
|
)->setRightTitle($fieldLabelsRight['Image']), |
82
|
|
|
TextField::create( |
83
|
|
|
'Title', |
84
|
|
|
$fieldLabels['Title'] |
85
|
|
|
)->setRightTitle($fieldLabelsRight['Title']), |
86
|
|
|
TextareaField::create( |
87
|
|
|
'Text', |
88
|
|
|
$fieldLabels['Text'] |
89
|
|
|
)->setRightTitle($fieldLabelsRight['Text']), |
90
|
|
|
DropdownField::create( |
91
|
|
|
'FontColour', |
92
|
|
|
$fieldLabels['FontColour'], |
93
|
|
|
Config::inst()->get('CallToAction', 'colour_font_options') |
94
|
|
|
)->setRightTitle($fieldLabelsRight['FontColour']), |
95
|
|
|
TextField::create( |
96
|
|
|
'CallToAction', |
97
|
|
|
$fieldLabels['CallToAction'] |
98
|
|
|
)->setRightTitle($fieldLabelsRight['CallToAction']), |
99
|
|
|
TreeDropdownField::create( |
100
|
|
|
'LinkID', |
101
|
|
|
$fieldLabels['Link'], |
102
|
|
|
'SiteTree' |
103
|
|
|
)->setRightTitle($fieldLabelsRight['Link']), |
104
|
|
|
DropdownField::create( |
105
|
|
|
'ImageFocusPoint', |
106
|
|
|
$fieldLabels['ImageFocusPoint'], |
107
|
|
|
$this->dbObject('ImageFocusPoint')->enumValues() |
108
|
|
|
)->setRightTitle($fieldLabelsRight['ImageFocusPoint']) |
109
|
|
|
] |
110
|
|
|
); |
111
|
|
|
$fields->removeByName('Pages'); |
112
|
|
|
|
113
|
|
|
return $fields; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
function CMSEditLink() |
|
|
|
|
117
|
|
|
{ |
118
|
|
|
return Director::absoluteBaseURL('/').'admin/calltoaction/CallToAction/EditForm/field/CallToAction/item/'.$this->ID.'/edit/'; |
|
|
|
|
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
function CMSAddLink() |
|
|
|
|
122
|
|
|
{ |
123
|
|
|
return Director::absoluteBaseURL('/').'/admin/calltoaction/CallToAction/EditForm/field/CallToAction/item/new'; |
|
|
|
|
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* left top |
128
|
|
|
*/ |
129
|
|
|
function BackgroundPosition() |
|
|
|
|
130
|
|
|
{ |
131
|
|
|
$str = 'center'; |
132
|
|
|
switch($this->ImageFocusPoint) { |
|
|
|
|
133
|
|
|
case 'Centre': $str = 'center'; break; |
|
|
|
|
134
|
|
|
case 'NE': $str = 'top right'; break; |
|
|
|
|
135
|
|
|
case 'E': $str = 'center right'; break; |
|
|
|
|
136
|
|
|
case 'SE': $str = 'bottom right'; break; |
|
|
|
|
137
|
|
|
case 'S': $str = 'bottom center'; break; |
|
|
|
|
138
|
|
|
case 'SW': $str = 'bottom left'; break; |
|
|
|
|
139
|
|
|
case 'W': $str = 'bottom left'; break; |
|
|
|
|
140
|
|
|
case 'NW': $str = 'top left'; break; |
|
|
|
|
141
|
|
|
case 'N': $str = 'top center'; break; |
|
|
|
|
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
return $str; |
145
|
|
|
} |
146
|
|
|
} |
147
|
|
|
|
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.