Test Setup Failed
Push — master ( 544e06...4e82f8 )
by Alexander
04:14
created

TreeInput::init()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 0
1
<?php
2
3
namespace devgroup\JsTreeWidget\widgets;
4
5
use DevGroup\Metronic\widgets\InputWidget;
6
use Yii;
7
use yii\helpers\ArrayHelper;
8
use yii\helpers\Html;
9
10
class TreeInput extends InputWidget
11
{
12
    public $treeConfig = [];
13
14
    public $multiple = false;
15
16
    public $selectIcon = 'fa fa-folder-o';
17
    public $selectText;
18
19
    public function init()
20
    {
21
        parent::init();
22
        if ($this->selectText === null) {
23
            $this->selectText = Yii::t('jstw', 'Select');
24
        }
25
    }
26
27
    public function run()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
28
    {
29
        $id = 'input_tree__' . $this->getId();
30
        $this->options['id'] = $id;
31
32
        if ($this->hasModel()) {
33
            $input = Html::activeHiddenInput($this->model, $this->attribute, $this->options);
34
        } else {
35
            $input = Html::hiddenInput($this->name, $this->value, $this->options);
36
        }
37
38
        $this->treeConfig['id'] = $id . '__tree';
39
        $oldOptions = isset($this->treeConfig['options']) ? $this->treeConfig['options'] : [];
40
        $this->treeConfig['options'] = ArrayHelper::merge($oldOptions, [
41
            'core' => [
42
                'multiple' => $this->multiple,
43
                'dblclick_toggle' => false,
44
            ],
45
        ]);
46
47
        return $this->render(
48
            'tree-input',
49
            [
50
                'id' => $id,
51
                'treeConfig' => $this->treeConfig,
52
                'multiple' => $this->multiple,
53
                'selectIcon' => $this->selectIcon,
54
                'selectText' => $this->selectText,
55
                'input' => $input,
56
            ]
57
        );
58
    }
59
}
60