Skip to content

Commit fc9a32e

Browse files
committed
Overwrites Current Link block to fit bootstrap markup
1 parent 8fa1ea0 commit fc9a32e

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

View/Element/Html/Link/Current.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
namespace Webgriffe\BootstrapMenu\View\Element\Html\Link;
4+
5+
class Current extends \Magento\Framework\View\Element\Html\Link\Current
6+
{
7+
protected function _toHtml()
8+
{
9+
if (false != $this->getTemplate()) {
10+
return parent::_toHtml();
11+
}
12+
13+
$highlight = '';
14+
15+
if ($this->getIsHighlighted() || $this->isCurrent()) {
16+
$highlight = ' active';
17+
}
18+
19+
$html = '<li class="nav item' . $highlight . '"><a href="' . $this->escapeHtml($this->getHref()) . '"';
20+
$html .= $this->getTitle()
21+
? ' title="' . $this->escapeHtml((string)new \Magento\Framework\Phrase($this->getTitle())) . '"'
22+
: '';
23+
$html .= $this->getAttributesHtml() . '>';
24+
25+
if ($this->getIsHighlighted()) {
26+
$html .= '<strong>';
27+
}
28+
29+
$html .= $this->escapeHtml((string)new \Magento\Framework\Phrase($this->getLabel()));
30+
31+
if ($this->getIsHighlighted()) {
32+
$html .= '</strong>';
33+
}
34+
35+
$html .= '</a></li>';
36+
37+
return $html;
38+
}
39+
}

etc/di.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
33
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
44
<preference for="Magento\Theme\Block\Html\Topmenu" type="Webgriffe\BootstrapMenu\Block\Html\Topmenu" />
5+
<preference for="Magento\Framework\View\Element\Html\Link\Current" type="Webgriffe\BootstrapMenu\View\Element\Html\Link\Current" />
56
</config>

0 commit comments

Comments
 (0)