Skip to content

Commit 625802f

Browse files
committed
add suffix/prefix options on nodes
1 parent f7ef121 commit 625802f

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

src/Nodes/AbstractNode.php

+24-3
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,20 @@ abstract class AbstractNode
3737
*/
3838
protected $icon;
3939

40+
/**
41+
* Optional HTML prefix for the node.
42+
*
43+
* @var string
44+
*/
45+
protected $prefix = '';
46+
47+
/**
48+
* Optional HTML suffix for the node.
49+
*
50+
* @var string
51+
*/
52+
protected $suffix = '';
53+
4054
/**
4155
* Array of icon resolvers.
4256
*
@@ -55,7 +69,7 @@ abstract class AbstractNode
5569
* @var array
5670
*/
5771
protected static $notHtmlAttributes = [
58-
'icon', 'href', 'affix', 'prefix', 'glyph',
72+
'icon', 'href', 'suffix', 'prefix', 'glyph',
5973
'glyphicon', 'fa-icon', 'fa-stack'
6074
];
6175

@@ -67,7 +81,7 @@ abstract class AbstractNode
6781
public static function addIconResolvers(array $resolvers)
6882
{
6983
static::$iconResolvers = $resolvers + static::$iconResolvers;
70-
static::$notHtmlAttributes = array_merge(['icon', 'href', 'affix', 'prefix'],
84+
static::$notHtmlAttributes = array_merge(['icon', 'href', 'suffix', 'prefix'],
7185
array_keys(static::$iconResolvers));
7286
}
7387

@@ -98,6 +112,13 @@ protected function parseAttributes(array $attributes)
98112
$attributes['class'] = [];
99113
}
100114

115+
if (isset($attributes['suffix'])) {
116+
$this->suffix = $attributes['suffix'];
117+
}
118+
if (isset($attributes['prefix'])) {
119+
$this->prefix = $attributes['prefix'];
120+
}
121+
101122
$attributes['id'] = isset($attributes['id']) ? $attributes['id'] : Str::slug($this->title);
102123

103124
return array_except($attributes, static::$notHtmlAttributes);
@@ -115,7 +136,7 @@ public function getId()
115136

116137
public function getTitle()
117138
{
118-
return $this->title;
139+
return $this->prefix.e($this->title).$this->suffix;
119140
}
120141

121142
public function getAttributes()

src/Renderers/ListRenderer.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ protected function renderAnchor($title, $href, array $attributes)
8282

8383
protected function getMenuTitle(NodeInterface $item)
8484
{
85-
return $this->renderItemIcon($item).e($item->getTitle());
85+
return $this->renderItemIcon($item).$item->getTitle();
8686
}
8787

8888
protected function renderItemIcon(NodeInterface $item)

0 commit comments

Comments
 (0)