|
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\FontAwesome; |
|
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
|
|
|
protected $iconCssPrefix; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @var array |
|
24
|
|
|
*/ |
|
25
|
|
|
protected $options = []; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @var array |
|
29
|
|
|
*/ |
|
30
|
|
|
protected $items = []; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @param string $iconCssPrefix |
|
34
|
|
|
* @param array $options |
|
35
|
|
|
*/ |
|
36
|
2 |
|
public function __construct($iconCssPrefix, $options = []) |
|
37
|
|
|
{ |
|
38
|
2 |
|
$this->iconCssPrefix = $iconCssPrefix; |
|
39
|
|
|
|
|
40
|
2 |
|
Html::addCssClass($options, FontAwesome::$basePrefix . '-ul'); |
|
41
|
|
|
|
|
42
|
2 |
|
$options['item'] = function ($item, $index) { |
|
43
|
2 |
|
return call_user_func($item, $index); |
|
44
|
|
|
}; |
|
45
|
|
|
|
|
46
|
2 |
|
$this->options = $options; |
|
47
|
2 |
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @return string |
|
51
|
|
|
*/ |
|
52
|
2 |
|
public function __toString() |
|
53
|
|
|
{ |
|
54
|
2 |
|
return Html::ul($this->items, $this->options); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* @param string $label |
|
59
|
|
|
* @param array $options |
|
60
|
|
|
* @return \rmrevin\yii\fontawesome\component\UnorderedList |
|
61
|
|
|
*/ |
|
62
|
|
|
public function item($label, $options = []) |
|
63
|
|
|
{ |
|
64
|
2 |
|
$this->items[] = function ($index) use ($label, $options) { |
|
|
|
|
|
|
65
|
2 |
|
$tag = ArrayHelper::remove($options, 'tag', 'li'); |
|
66
|
|
|
|
|
67
|
2 |
|
$icon = ArrayHelper::remove($options, 'icon'); |
|
68
|
2 |
|
$icon = empty($icon) |
|
69
|
1 |
|
? null |
|
70
|
2 |
|
: (is_string($icon) ? (string)(new Icon($this->iconCssPrefix, $icon))->li() : $icon); |
|
71
|
|
|
|
|
72
|
2 |
|
$content = trim($icon . $label); |
|
73
|
|
|
|
|
74
|
2 |
|
return Html::tag($tag, $content, $options); |
|
75
|
|
|
}; |
|
76
|
|
|
|
|
77
|
2 |
|
return $this; |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.