Select::setMultiple()   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
eloc 1
c 1
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
        $this->setNulloption();
32
        $this->setMultiple();
33
    }
34
35
    protected function setOptions()
36
    {
37
        if (isset($this->params['options']) && ! empty($this->params['options'])) {
38
            $this->options = $this->params['options'];
39
40
            foreach ($this->options as $value => $label) {
41
                if (is_array($this->value)) {
42
                    if (in_array($value, $this->value)) {
43
                        $this->selected[] = $value;
44
                    }
45
                } else {
46
                    if ($value == $this->value) {
47
                        $this->selected[] = $value;
48
                    }
49
                }
50
            }
51
        }
52
    }
53
54
    protected function setNulloption()
55
    {
56
        $this->nulloption = $this->params->get('nulloption');
57
    }
58
59
    protected function setMultiple()
60
    {
61
        $this->multiple = $this->params->get('multiple');
62
    }
63
64
    protected function setStyles()
65
    {
66
        $this->class[] = config('blade-form-components.themes.'.$this->getTheme().'.fields.select') ?? config('blade-form-components.themes.'.$this->getTheme().'.fields.default');
67
        $this->labelClass[] = config('blade-form-components.themes.'.$this->getTheme().'.labels.default');
68
    }
69
}
70