|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
|
|
5
|
|
|
class ThemeCustomisation extends DataObject { |
|
|
|
|
|
|
6
|
|
|
|
|
7
|
|
|
private static $location_for_scss_file = 'themes/main_mysite/src/variables/_themecustomisation.scss'; |
|
|
|
|
|
|
8
|
|
|
|
|
9
|
|
|
private static $singular_name = 'Theme Customisation'; |
|
|
|
|
|
|
10
|
|
|
|
|
11
|
|
|
function i18n_singular_name() |
|
|
|
|
|
|
12
|
|
|
{ |
|
13
|
|
|
return _t('ThemeCustomiser.SINGULAR_NAME', 'Theme Customisation'); |
|
14
|
|
|
} |
|
15
|
|
|
|
|
16
|
|
|
private static $plural_name = 'Theme Customisations'; |
|
|
|
|
|
|
17
|
|
|
|
|
18
|
|
|
function i18n_plural_name() |
|
|
|
|
|
|
19
|
|
|
{ |
|
20
|
|
|
return _t('ThemeCustomiser.PLURAL_NAME', 'Theme Customisations'); |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
private static $db = [ |
|
|
|
|
|
|
24
|
|
|
'BackgroundColour' => 'Color', |
|
25
|
|
|
'FontColour' => 'Color', |
|
26
|
|
|
'Accent1Colour' => 'Color', |
|
27
|
|
|
'Accent2Colour' => 'Color', |
|
28
|
|
|
'MenuBarBackgroundColour' => 'Color', |
|
29
|
|
|
'LinkColour' => 'Color', |
|
30
|
|
|
'ActiveColour' => 'Color', |
|
31
|
|
|
'HeaderFont' => 'Varchar(50)', |
|
32
|
|
|
'TextFont' => 'Varchar(50)', |
|
33
|
|
|
'MonoFont' => 'Varchar(50)' |
|
34
|
|
|
]; |
|
35
|
|
|
|
|
36
|
|
|
private static $has_one = [ |
|
|
|
|
|
|
37
|
|
|
'LargeLogo' => 'Image', |
|
38
|
|
|
'SmallLogo' => 'Image' |
|
39
|
|
|
]; |
|
40
|
|
|
|
|
41
|
|
|
private static $summary_fields = [ |
|
|
|
|
|
|
42
|
|
|
'LargeLogo.Stripthumbnail' => 'Name' |
|
43
|
|
|
]; |
|
44
|
|
|
|
|
45
|
|
|
private static $field_labels = [ |
|
|
|
|
|
|
46
|
|
|
'MonoFont' => 'Mono spaced font' |
|
47
|
|
|
]; |
|
48
|
|
|
|
|
49
|
|
|
private static $field_labels_right = [ |
|
|
|
|
|
|
50
|
|
|
'MonoFont' => 'Font similar to courier with identical width used for each character - great for numbers.' |
|
51
|
|
|
]; |
|
52
|
|
|
|
|
53
|
|
|
|
|
54
|
|
|
public function CMSEditLink() |
|
55
|
|
|
{ |
|
56
|
|
|
$controller = singleton("ThemeCustomiser"); |
|
57
|
|
|
|
|
58
|
|
|
return $controller->Link().$this->ClassName."/EditForm/field/".$this->ClassName."/item/".$this->ID."/edit"; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
public function CMSAddLink() |
|
62
|
|
|
{ |
|
63
|
|
|
$controller = singleton("ThemeCustomiser"); |
|
64
|
|
|
|
|
65
|
|
|
return $controller->Link().$this->ClassName."/EditForm/field/".$this->ClassName."/item/new"; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
public function getCMSFields() |
|
69
|
|
|
{ |
|
70
|
|
|
$fields = parent::getCMSFields(); |
|
71
|
|
|
|
|
72
|
|
|
$fontList = Injector::inst()->get('GoogleFontProvider')->fullList(); |
|
73
|
|
|
$fontFields = $this->Config()->get('font_fields'); |
|
|
|
|
|
|
74
|
|
|
$labels = $this->FieldLabels(); |
|
75
|
|
|
foreach($this->fontFields() as $fontField) { |
|
76
|
|
|
$fields->replaceField( |
|
77
|
|
|
$fontField, |
|
78
|
|
|
DropdownField::create( |
|
79
|
|
|
$fontField, |
|
80
|
|
|
$labels[$fontField], |
|
81
|
|
|
['' => '-- select --'] + $fontList |
|
82
|
|
|
) |
|
83
|
|
|
); |
|
84
|
|
|
} |
|
85
|
|
|
foreach($this->colourFields() as $colourField) { |
|
86
|
|
|
$fields->replaceField( |
|
87
|
|
|
$colourField, |
|
88
|
|
|
ColorField::create( |
|
89
|
|
|
$colourField, |
|
90
|
|
|
$labels[$colourField] |
|
91
|
|
|
) |
|
92
|
|
|
); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
$rightFieldDescriptions = $this->Config()->get('field_labels_right'); |
|
96
|
|
|
foreach($rightFieldDescriptions as $field => $desc) { |
|
97
|
|
|
$field = $fields->DataFieldByName($field); |
|
98
|
|
|
if($field) { |
|
99
|
|
|
$field->setDescription($desc); |
|
100
|
|
|
} |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
return $fields; |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* exports to variable SCSS file ... |
|
108
|
|
|
*/ |
|
109
|
|
|
function exportToThemeSCSS() |
|
|
|
|
|
|
110
|
|
|
{ |
|
111
|
|
|
|
|
112
|
|
|
$location = Director::baseFolder() .'/'. $this->Config()->get('location_for_scss_file'); |
|
113
|
|
|
$data = $this->renderWith('ThemeCustomisationSCSSOutput'); |
|
114
|
|
|
file_put_contents($location, $data); |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
/** |
|
118
|
|
|
* stuff to be inserted into head of html |
|
119
|
|
|
* - custom css |
|
120
|
|
|
* - link to google fonts ... |
|
121
|
|
|
*/ |
|
122
|
|
|
function htmlForPageHeader() |
|
|
|
|
|
|
123
|
|
|
{ |
|
124
|
|
|
$list = []; |
|
125
|
|
|
foreach($this->fontFields() as $fontField) { |
|
126
|
|
|
$list[$this->$fontField] = $this->$fontField; |
|
127
|
|
|
} |
|
128
|
|
|
$fontList = Injecton::inst()->get('GoogleFontProvider')->getLink($list); |
|
129
|
|
|
|
|
130
|
|
|
return $fontList; |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
function canCreate($member = null) |
|
|
|
|
|
|
134
|
|
|
{ |
|
135
|
|
|
if(ThemeCustomisation::get()->count()) { |
|
136
|
|
|
return false; |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
return parent::canCreate($member); |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
function canDelete($member = null) |
|
|
|
|
|
|
143
|
|
|
{ |
|
144
|
|
|
return false; |
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
|
|
protected function fontFields() |
|
148
|
|
|
{ |
|
149
|
|
|
return $this->fieldsPerType('Font'); |
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
|
|
protected function colourFields() |
|
153
|
|
|
{ |
|
154
|
|
|
return $this->fieldsPerType('Colour'); |
|
155
|
|
|
} |
|
156
|
|
|
|
|
157
|
|
|
protected function fieldsPerType($name) |
|
158
|
|
|
{ |
|
159
|
|
|
$list = $this->Config()->get('db'); |
|
160
|
|
|
foreach($list as $key => $type) { |
|
161
|
|
|
if(substr($key, strlen($name) * -1) === $name) { |
|
162
|
|
|
$newList[$key] = $key; |
|
|
|
|
|
|
163
|
|
|
} |
|
164
|
|
|
} |
|
165
|
|
|
return $newList; |
|
|
|
|
|
|
166
|
|
|
} |
|
167
|
|
|
|
|
168
|
|
|
} |
|
169
|
|
|
|
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.