1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* UnorderedList.php |
4
|
|
|
* @author Revin Roman |
5
|
|
|
* @link https://rmrevin.com |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace rmrevin\yii\fontawesome\component; |
9
|
|
|
|
10
|
|
|
use rmrevin\yii\fontawesome\FA; |
11
|
|
|
use yii\helpers\ArrayHelper; |
12
|
|
|
use yii\helpers\Html; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Class UnorderedList |
16
|
|
|
* @package rmrevin\yii\fontawesome\component |
17
|
|
|
*/ |
18
|
|
|
class UnorderedList |
19
|
|
|
{ |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @deprecated |
23
|
|
|
* @var string |
24
|
|
|
*/ |
25
|
|
|
public static $defaultTag = 'ul'; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @deprecated |
29
|
|
|
* @var string |
30
|
|
|
*/ |
31
|
|
|
private $tag; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var array |
35
|
|
|
*/ |
36
|
|
|
protected $options = []; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @var array |
40
|
|
|
*/ |
41
|
|
|
protected $items = []; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @param array $options |
45
|
|
|
*/ |
46
|
1 |
|
public function __construct($options = []) |
47
|
|
|
{ |
48
|
|
|
Html::addCssClass($options, FA::$cssPrefix . '-ul'); |
49
|
|
|
|
50
|
|
|
$options['item'] = function ($item, $index) { |
51
|
|
|
return call_user_func($item, $index); |
52
|
1 |
|
}; |
53
|
|
|
|
54
|
1 |
|
$this->options = $options; |
55
|
1 |
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @return string |
59
|
|
|
*/ |
60
|
|
|
public function __toString() |
61
|
|
|
{ |
62
|
|
|
return Html::ul($this->items, $this->options); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @param string $label |
67
|
|
|
* @param array $options |
68
|
|
|
* @return static |
69
|
|
|
*/ |
70
|
|
|
public function item($label, $options = []) |
71
|
|
|
{ |
72
|
1 |
|
$this->items[] = function ($index) use ($label, $options) { |
|
|
|
|
73
|
|
|
$tag = ArrayHelper::remove($options, 'tag', 'li'); |
74
|
|
|
|
75
|
|
|
$icon = ArrayHelper::remove($options, 'icon'); |
76
|
1 |
|
$icon = empty($icon) |
77
|
|
|
? null |
78
|
|
|
: (is_string($icon) ? (string)(new Icon($icon))->li() : $icon); |
79
|
|
|
|
80
|
|
|
$content = trim($icon . $label); |
81
|
|
|
|
82
|
|
|
return Html::tag($tag, $content, $options); |
83
|
1 |
|
}; |
84
|
|
|
|
85
|
1 |
|
return $this; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @deprecated |
90
|
|
|
* Change html tag. |
91
|
|
|
* @param string $tag |
92
|
|
|
* @return static |
93
|
|
|
* @throws \yii\base\InvalidParamException |
94
|
|
|
*/ |
95
|
1 |
|
public function tag($tag) |
96
|
|
|
{ |
97
|
1 |
|
$this->tag = $tag; |
|
|
|
|
98
|
|
|
|
99
|
1 |
|
$this->options['tag'] = $tag; |
100
|
|
|
|
101
|
1 |
|
return $this; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @deprecated |
106
|
|
|
* @param string|null $tag |
107
|
|
|
* @param array $options |
108
|
|
|
* @return string |
109
|
|
|
* @throws \yii\base\InvalidConfigException |
110
|
|
|
*/ |
111
|
|
View Code Duplication |
public function render($tag = null, $options = []) |
|
|
|
|
112
|
|
|
{ |
113
|
|
|
$tag = empty($tag) |
114
|
|
|
? (empty($this->tag) ? static::$defaultTag : $this->tag) |
|
|
|
|
115
|
|
|
: $tag; |
116
|
|
|
|
117
|
|
|
$options = array_merge($this->options, $options); |
118
|
|
|
|
119
|
|
|
$items = $this->items; |
120
|
|
|
|
121
|
|
|
return Html::tag($tag, implode($items), $options); |
122
|
|
|
} |
123
|
|
|
} |
124
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.