Completed
Push — master ( a94554...39eef4 )
by Costin
02:09
created

Select::setDefaultClass()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
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
    }
32
33
    protected function setOptions()
34
    {
35
        if (isset($this->params['options']) && ! empty($this->params['options'])) {
36
            $this->options = $this->params['options'];
37
38
            foreach ($this->options as $value => $label) {
39
                if (is_array($this->value)) {
40
                    if (in_array($value, $this->value)) {
41
                        $this->selected[] = $value;
42
                    }
43
                } else {
44
                    if ($value == $this->value) {
45
                        $this->selected[] = $value;
46
                    }
47
                }
48
            }
49
        }
50
    }
51
    
52
    protected function setDefaultClass()
53
    {
54
        $this->class[] = config('blade-form-components.themes.'.$this->getTheme().'.fields.select');
55
    }
56
}
57