Passed
Push — master ( 1ea92e...59050e )
by Robbie
02:21 queued 10s
created

FontPickerField::Value()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

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