Skip to content

Commit 09609b1

Browse files
author
Thitithan Atthakasem
committed
Implement Menu::generateBreadcrumb()
1 parent 6b315c8 commit 09609b1

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/Menu.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Atthakasem\LaravelJsonMenu;
44

5+
use DOMNodeList;
56
use Illuminate\Support\Collection;
67

78
class Menu
@@ -19,6 +20,22 @@ public function __construct($structure)
1920
}
2021
}
2122

23+
public function generateBreadcrumb(DOMNodeList $activeLinks): string
24+
{
25+
$html = '<ul>';
26+
foreach ($activeLinks as $key => $link) {
27+
$active = $key === count($activeLinks) - 1 ? 'active' : '';
28+
$html .= '<li>
29+
<a href="' . $link->getAttribute('href') . '" class="' . $active . '">' .
30+
$link->nodeValue .
31+
'</a>
32+
</li>';
33+
}
34+
$html .= '</ul>';
35+
36+
return $this->stripWhitespaces($html);
37+
}
38+
2239
public function generateHtml(): string
2340
{
2441
$html = '<ul>';

0 commit comments

Comments
 (0)