Skip to content

Commit 7c09517

Browse files
author
okarpenko
committed
MAGETWO-30068: Customer menu tabs aren't displayed as selected for child pages
1 parent 35e1393 commit 7c09517

File tree

6 files changed

+68
-41
lines changed

6 files changed

+68
-41
lines changed

app/code/Magento/Sales/Controller/AbstractController/View.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public function execute()
5252
$resultPage = $this->resultPageFactory->create();
5353
$resultPage->getLayout()->initMessages();
5454

55+
/** @var \Magento\Framework\View\Element\Html\Links $navigationBlock */
5556
$navigationBlock = $resultPage->getLayout()->getBlock('customer_account_navigation');
5657
if ($navigationBlock) {
5758
$navigationBlock->setActive('sales/order/history');

app/code/Magento/Theme/etc/di.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,4 @@
7676
</arguments>
7777
</type>
7878
<preference for="Magento\Framework\View\Model\PageLayout\Config\BuilderInterface" type="Magento\Theme\Model\PageLayout\Config\Builder"/>
79-
<type name="Magento\Framework\View\Element\Html\Link\Current">
80-
<plugin name="saleOrderViewMenu" type="Magento\Framework\View\Plugin\Element\Html\Link\Current"/>
81-
</type>
8279
</config>

lib/internal/Magento/Framework/View/Element/Html/Link/Current.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,19 @@ protected function _toHtml()
110110
$html .= $this->getTitle()
111111
? ' title="' . $this->escapeHtml((string)new \Magento\Framework\Phrase($this->getTitle())) . '"'
112112
: '';
113-
$html .= '>' . $this->escapeHtml((string)new \Magento\Framework\Phrase($this->getLabel())) . '</a></li>';
113+
$html .= '>';
114+
115+
if ($this->getIsHighlighted()) {
116+
$html .= '<strong>';
117+
}
118+
119+
$html .= $this->escapeHtml((string)new \Magento\Framework\Phrase($this->getLabel()));
120+
121+
if ($this->getIsHighlighted()) {
122+
$html .= '</strong>';
123+
}
124+
125+
$html .= '</a></li>';
114126
}
115127

116128
return $html;

lib/internal/Magento/Framework/View/Element/Html/Links.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,35 @@ public function getLinks()
2020
return $this->_layout->getChildBlocks($this->getNameInLayout());
2121
}
2222

23+
/**
24+
* Find link by path
25+
*
26+
* @param string $path
27+
* @return \Magento\Framework\View\Element\Html\Link
28+
*/
29+
protected function getLinkByPath($path)
30+
{
31+
foreach ($this->getLinks() as $link) {
32+
if ($link->getPath() == $path) {
33+
return $link;
34+
}
35+
}
36+
}
37+
38+
/**
39+
* Set active link
40+
*
41+
* @param string $path
42+
* @return void
43+
*/
44+
public function setActive($path)
45+
{
46+
$link = $this->getLinkByPath($path);
47+
if ($link) {
48+
$link->setIsHighlighted(true);
49+
}
50+
}
51+
2352
/**
2453
* Render Block
2554
*

lib/internal/Magento/Framework/View/Plugin/Element/Html/Link/Current.php

Lines changed: 0 additions & 37 deletions
This file was deleted.

lib/internal/Magento/Framework/View/Test/Unit/Element/Html/LinksTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,31 @@ public function testGetLinks()
4949
$this->assertEquals($blocks, $this->_block->getLinks());
5050
}
5151

52+
public function testSetActive()
53+
{
54+
$link = $this->getMock('Magento\Framework\View\Element\Html\Link', [], [], '', false);
55+
$link
56+
->expects($this->at(1))
57+
->method('__call')
58+
->with('setIsHighlighted', [true]);
59+
$link
60+
->expects($this->at(0))
61+
->method('__call')
62+
->with('getPath', [])
63+
->willReturn('test/path');
64+
65+
$name = 'test_name';
66+
$this->_context->getLayout()
67+
->expects($this->once())
68+
->method('getChildBlocks')
69+
->with($name)
70+
->willReturn([$link]);
71+
72+
$this->_block->setNameInLayout($name);
73+
74+
$this->_block->setActive('test/path');
75+
}
76+
5277
public function testRenderLink()
5378
{
5479
$blockHtml = 'test';

0 commit comments

Comments
 (0)