Passed
Push — master ( 567445...4ac224 )
by Costin
02:45
created

Select::setStyles()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace SoareCostin\BladeFormComponents\FormElements;
4
5
use SoareCostin\BladeFormComponents\FormElement;
6
7
class Select extends FormElement
8
{
9
    /** @var array */
10
    public $options = [];
11
12
    /** @var bool */
13
    public $multiple = false;
14
15
    /** @var string */
16
    public $nulloption;
17
18
    /** @var array */
19
    public $selected = [];
20
21
    protected function attributesList()
22
    {
23
        return [
24
            'id', 'name', 'class', 'multiple', 'required', 'disabled', 'readonly', 'autocomplete',
25
        ];
26
    }
27
28
    protected function setSpecificAttributes()
29
    {
30
        $this->setOptions();
31
        $this->setNulloption();
32
    }
33
34
    protected function setOptions()
35
    {
36
        if (isset($this->params['options']) && ! empty($this->params['options'])) {
37
            $this->options = $this->params['options'];
38
39
            foreach ($this->options as $value => $label) {
40
                if (is_array($this->value)) {
41
                    if (in_array($value, $this->value)) {
42
                        $this->selected[] = $value;
43
                    }
44
                } else {
45
                    if ($value == $this->value) {
46
                        $this->selected[] = $value;
47
                    }
48
                }
49
            }
50
        }
51
    }
52
53
    protected function setNulloption()
54
    {
55
        $this->nulloption = $this->params->get('nulloption');
56
    }
57
58
    protected function setStyles()
59
    {
60
        $this->class[] = config('blade-form-components.themes.'.$this->getTheme().'.fields.select') ?? config('blade-form-components.themes.'.$this->getTheme().'.fields.default');
61
        $this->labelClass[] = config('blade-form-components.themes.'.$this->getTheme().'.labels.default');
62
    }
63
}
64