Skip to content

Commit 29640f1

Browse files
committed
Comparing the current block path with the current url path
1 parent 9186f4a commit 29640f1

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

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

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
*/
66
namespace Magento\Framework\View\Element\Html\Link;
77

8+
use Magento\Framework\App\DefaultPathInterface;
9+
use Magento\Framework\View\Element\Template;
10+
use Magento\Framework\View\Element\Template\Context;
11+
812
/**
913
* Block representing link with two possible states.
1014
* "Current" state means link leads to URL equivalent to URL of currently displayed page.
@@ -17,25 +21,25 @@
1721
* @method null|bool getCurrent()
1822
* @method \Magento\Framework\View\Element\Html\Link\Current setCurrent(bool $value)
1923
*/
20-
class Current extends \Magento\Framework\View\Element\Template
24+
class Current extends Template
2125
{
2226
/**
2327
* Default path
2428
*
25-
* @var \Magento\Framework\App\DefaultPathInterface
29+
* @var DefaultPathInterface
2630
*/
2731
protected $_defaultPath;
2832

2933
/**
3034
* Constructor
3135
*
32-
* @param \Magento\Framework\View\Element\Template\Context $context
33-
* @param \Magento\Framework\App\DefaultPathInterface $defaultPath
36+
* @param Context $context
37+
* @param DefaultPathInterface $defaultPath
3438
* @param array $data
3539
*/
3640
public function __construct(
37-
\Magento\Framework\View\Element\Template\Context $context,
38-
\Magento\Framework\App\DefaultPathInterface $defaultPath,
41+
Context $context,
42+
DefaultPathInterface $defaultPath,
3943
array $data = []
4044
) {
4145
parent::__construct($context, $data);
@@ -81,7 +85,7 @@ private function getMca()
8185
*/
8286
public function isCurrent()
8387
{
84-
return $this->getCurrent() || $this->getUrl($this->getPath()) == $this->getUrl($this->getMca());
88+
return $this->getCurrent() || $this->getUrl($this->getPath()) == $this->getUrl($this->getPathInfo());
8589
}
8690

8791
/**
@@ -147,4 +151,14 @@ private function getAttributesHtml()
147151

148152
return $attributesHtml;
149153
}
154+
155+
/**
156+
* Get current page path info
157+
*
158+
* @return string
159+
*/
160+
private function getPathInfo()
161+
{
162+
return trim($this->_request->getPathInfo(), '/');
163+
}
150164
}

0 commit comments

Comments
 (0)