-
Notifications
You must be signed in to change notification settings - Fork 11
/
FontPickerField.php
46 lines (36 loc) · 1.04 KB
/
FontPickerField.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
namespace CWP\AgencyExtensions\Forms;
use SilverStripe\Forms\SingleSelectField;
class FontPickerField extends SingleSelectField
{
/**
* The default value if none is already configured
*
* @var string
*/
const DEFAULT_VALUE = 'nunito-sans';
public function __construct($name, $title = null, $source = array(), $value = null)
{
parent::__construct($name, $title, $source, $value);
$this->addExtraClass('font-picker-field');
}
public function getSchemaDataDefaults()
{
$schemaData = parent::getSchemaDataDefaults();
$fonts = [];
foreach ($this->getSource() as $css => $title) {
$fonts[] = [
'CSSClass' => $css,
'Title' => $title,
];
}
$schemaData['source'] = $fonts;
$schemaData['name'] = $this->getName();
$schemaData['value'] = $this->Value();
return $schemaData;
}
public function Value()
{
return parent::Value() ?: self::DEFAULT_VALUE;
}
}