Button::init()   A
last analyzed

Complexity

Conditions 4
Paths 8

Size

Total Lines 14
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 14
rs 9.9332
c 0
b 0
f 0
cc 4
nc 8
nop 0
1
<?php
2
namespace backend\widgets;
3
4
use yii\bootstrap\Button as BaseButton;
5
use yii\bootstrap\Html;
6
use yii\helpers\Url;
7
8
/**
9
 * Renders a bootstrap button with links support.
10
 *
11
 * For example,
12
 *
13
 * ```php
14
 * echo Button::widget([
15
 *     'label' => 'Action',
16
 *     'link' => 'some-link',
17
 *     'buttonClass' => 'btn-info',
18
 * ]);
19
 * ```
20
 * @see http://getbootstrap.com/javascript/#buttons
21
 */
22
class Button extends BaseButton
23
{
24
    /**
25
     * @var string | null
26
     */
27
    public $link;
28
29
    /**
30
     * @var string | null
31
     */
32
    public $buttonType = 'default';
33
34
    /**
35
     * @var string | null
36
     */
37
    public $iconClass;
38
39
    /**
40
     * @inheritdoc
41
     */
42
    public $encodeLabel = false;
43
44
    /**
45
     * @inheritdoc
46
     */
47
    public function init()
48
    {
49
        parent::init();
50
        if ($this->link) {
51
            $this->tagName = 'a';
52
            $this->options['href'] = Url::to($this->link);
53
        }
54
        if ($this->buttonType) {
55
            Html::addCssClass($this->options, 'btn-'.$this->buttonType);
56
        }
57
        if ($this->iconClass) {
58
            $this->label = Html::tag('span', '', [
59
                'class' => $this->iconClass,
60
            ]) . ' ' . $this->label;
61
        }
62
    }
63
}
64