ColorField::requirements()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
namespace LeKoala\FormElements;
4
5
use SilverStripe\Forms\TextField;
6
use SilverStripe\View\Requirements;
7
8
/**
9
 * @link https://github.com/mdbassit/Coloris
10
 * @link https://gist.github.com/lekoala/233b0c6246170716c52dbfab342caf22
11
 * @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/color
12
 */
13
class ColorField extends TextField implements LocalizableField
14
{
15
    use BaseElement;
16
    use Localize;
17
18
    /**
19
     * Override locale. If empty will default to current locale
20
     *
21
     * @var string
22
     */
23
    protected $locale = null;
24
25
    /**
26
     * @config
27
     * @var array
28
     */
29
    private static $default_config = [];
0 ignored issues
show
introduced by
The private property $default_config is not used, and could be removed.
Loading history...
30
31
    /**
32
     * @config
33
     * @var boolean
34
     */
35
    private static $enable_requirements = true;
0 ignored issues
show
introduced by
The private property $enable_requirements is not used, and could be removed.
Loading history...
36
37
    public function __construct($name, $title = null, $value = '', $maxLength = null, $form = null)
38
    {
39
        parent::__construct($name, $title, $value, $maxLength, $form);
40
        $this->mergeDefaultConfig();
41
    }
42
43
    public function getInputType()
44
    {
45
        return 'text';
46
    }
47
48
    public function Type()
49
    {
50
        return 'coloris';
51
    }
52
53
    public function getSwatches()
54
    {
55
        return $this->getConfig('swatches');
56
    }
57
58
    public function setSwatches($values)
59
    {
60
        $this->setConfig('swatches', $values);
61
    }
62
63
    public function Field($properties = array())
64
    {
65
        return $this->wrapInElement('coloris-input', $properties);
66
    }
67
68
    public static function requirements()
69
    {
70
        Requirements::javascript("lekoala/silverstripe-form-elements: client/custom-elements/coloris-input.min.js");
71
    }
72
}
73