Completed
Push — master ( 2d17d3...8330e8 )
by Alexey
05:52
created

IconPicker   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 5
dl 0
loc 36
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A run() 0 9 2
A registerClientScript() 0 10 1
1
<?php
2
3
namespace dominus77\iconpicker;
4
5
use Yii;
6
use yii\helpers\Html;
7
use yii\helpers\Json;
8
use yii\widgets\InputWidget;
9
10
/**
11
 * Class IconPicker
12
 * @package dominus77\iconpicker
13
 */
14
class IconPicker extends InputWidget
15
{
16
    /**
17
     * Options plugin
18
     * @var array
19
     * @see https://farbelous.github.io/fontawesome-iconpicker/
20
     */
21
    public $clientOptions = [];
22
23
    /**
24
     * @inheritdoc
25
     */
26 2
    public function run()
27
    {
28 2
        if ($this->hasModel()) {
29 1
            echo Html::activeTextInput($this->model, $this->attribute, $this->options);
30
        } else {
31 1
            echo Html::textInput($this->name, $this->value, $this->options);
32
        }
33 2
        $this->registerClientScript();
34 2
    }
35
36
    /**
37
     * Publish resource
38
     */
39 2
    protected function registerClientScript()
40
    {
41 2
        $js = [];
42 2
        $view = $this->getView();
43 2
        IconPickerAsset::register($view);
44 2
        $id = $this->options['id'];
45 2
        $options = Json::encode($this->clientOptions);
46 2
        $js[] = "$('#{$id}').iconpicker($options);";
47 2
        $view->registerJs(implode("\n", $js));
48 2
    }
49
}
50