-
Notifications
You must be signed in to change notification settings - Fork 0
/
ButtonGroup.php
79 lines (71 loc) · 2.14 KB
/
ButtonGroup.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
/**
* @link http://foundationize.com
* @package shqear/yii2-foundation6
* @version 1.0.0
*/
namespace shqear\foundation6;
use yii\helpers\Html;
use yii\helpers\ArrayHelper;
/**
* Description of ButtonGroup
*
* @see http://foundation.zurb.com/docs/components/button_groups.html
*/
class ButtonGroup extends Widget
{
/**
* @var array list of buttons. Each array element represents a single button
* which can be specified as a string or an array of the following structure:
*
* - label: string, required, the button label.
* - url: string|array, optional, the url for the button link
* - options: array, optional, the HTML attributes of the button.
*/
public $buttons = [];
/**
* @var boolean whether to HTML-encode the button labels.
*/
public $encodeLabels = true;
/**
* Initializes the widget.
* If you override this method, make sure you call the parent implementation first.
*/
public function init()
{
parent::init();
Html::addCssClass($this->options, 'button-group');
}
/**
* Renders the widget.
*/
public function run()
{
echo Html::tag('ul', $this->renderButtons(), $this->options);
}
/**
* Generates the buttons that compound the group as specified on [[buttons]].
* @return string the rendering result.
*/
protected function renderButtons()
{
$buttons = [];
foreach ($this->buttons as $button) {
if (is_array($button)) {
$label = ArrayHelper::getValue($button, 'label');
$url = ArrayHelper::getValue($button, 'url');
$options = ArrayHelper::getValue($button, 'options');
$button = Button::widget([
'label' => $label,
'url' => $url,
'options' => $options,
'encodeLabel' => $this->encodeLabels
]);
$buttons[] = Html::tag('li', $button);
} else {
$buttons[] = Html::tag('li', $button);
}
}
return implode("\n", $buttons);
}
}