Completed
Push — master ( 839e9e...4e091b )
by Costin
03:53
created

Select::setOptions()   B

Complexity

Conditions 7
Paths 6

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 18
rs 8.8333
c 0
b 0
f 0
cc 7
nc 6
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
    /** @var array */
22
    public $attributesList = [
23
        'id', 'name', 'class', 'multiple', 'required', 'disabled', 'readonly', 'autocomplete'
24
    ];
25
26
    protected function setSpecificAttributes()
27
    {
28
        $this->setOptions();
29
    }
30
31
    protected function setOptions()
32
    {
33
        if (isset($this->params['options']) && !empty($this->params['options'])) {
34
            $this->options = $this->params['options'];
35
36
            foreach ($this->options as $value => $label) {
37
                if (is_array($this->value)) {
38
                    if (in_array($value, $this->value)) {
39
                        $this->selected[] = $value;
40
                    }
41
                } else {
42
                    if ($value == $this->value) {
43
                        $this->selected[] = $value;
44
                    }
45
                }
46
            }
47
        }
48
    }
49
}