-
Notifications
You must be signed in to change notification settings - Fork 0
/
Breadcrumbs.php
79 lines (70 loc) · 1.95 KB
/
Breadcrumbs.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 shqear\foundation6\helpers\Html;
use Yii;
/**
* Description of Breadcrumbs
*
* @property string icon
*/
class Breadcrumbs extends \yii\widgets\Breadcrumbs
{
public $options = ['class' => 'breadcrumbs'];
public $_icon = null;
public $activeItemTemplate = "<li class=\"current\">{link}</li>\n";
public $iconItemTemplate = "<li class=\"marker\">{link}</li>\n";
public function run()
{
if (empty($this->links)) {
return;
}
$links = [];
if ($this->icon) {
$links[] = $this->renderItem([
'label' => "<i class=\"{$this->icon}\"></i>",
'encode' => false], $this->iconItemTemplate);
}
if ($this->homeLink === null) {
$links[] = $this->renderItem([
'label' => Yii::t('yii', 'Home'),
'url' => Yii::$app->homeUrl,
], $this->itemTemplate);
} elseif ($this->homeLink !== false) {
$links[] = $this->renderItem($this->homeLink, $this->itemTemplate);
}
foreach ($this->links as $link) {
if (!is_array($link)) {
$link = ['label' => $link];
}
$links[] = $this->renderItem($link, isset($link['url']) ? $this->itemTemplate : $this->activeItemTemplate);
}
echo Html::tag($this->tag, implode('', $links), $this->options);
}
/**
* @return string
*/
public function getIcon()
{
return $this->_icon;
}
/**
* @param string $icon
*/
public function setIcon($icon)
{
if (is_null($icon)) {
$this->_icon = null;
return;
}
if (preg_match('/fa fa-.*/', $icon)) {
$this->_icon = $icon;
} else {
$this->_icon = 'fa fa-' . $icon;
}
}
}