Skip to content

Commit

Permalink
Comparing the current block path with the current url path
Browse files Browse the repository at this point in the history
  • Loading branch information
eduard13 committed Nov 7, 2018
1 parent 9186f4a commit 29640f1
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions lib/internal/Magento/Framework/View/Element/Html/Link/Current.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
*/
namespace Magento\Framework\View\Element\Html\Link;

use Magento\Framework\App\DefaultPathInterface;
use Magento\Framework\View\Element\Template;
use Magento\Framework\View\Element\Template\Context;

/**
* Block representing link with two possible states.
* "Current" state means link leads to URL equivalent to URL of currently displayed page.
Expand All @@ -17,25 +21,25 @@
* @method null|bool getCurrent()
* @method \Magento\Framework\View\Element\Html\Link\Current setCurrent(bool $value)
*/
class Current extends \Magento\Framework\View\Element\Template
class Current extends Template
{
/**
* Default path
*
* @var \Magento\Framework\App\DefaultPathInterface
* @var DefaultPathInterface
*/
protected $_defaultPath;

/**
* Constructor
*
* @param \Magento\Framework\View\Element\Template\Context $context
* @param \Magento\Framework\App\DefaultPathInterface $defaultPath
* @param Context $context
* @param DefaultPathInterface $defaultPath
* @param array $data
*/
public function __construct(
\Magento\Framework\View\Element\Template\Context $context,
\Magento\Framework\App\DefaultPathInterface $defaultPath,
Context $context,
DefaultPathInterface $defaultPath,
array $data = []
) {
parent::__construct($context, $data);
Expand Down Expand Up @@ -81,7 +85,7 @@ private function getMca()
*/
public function isCurrent()
{
return $this->getCurrent() || $this->getUrl($this->getPath()) == $this->getUrl($this->getMca());
return $this->getCurrent() || $this->getUrl($this->getPath()) == $this->getUrl($this->getPathInfo());
}

/**
Expand Down Expand Up @@ -147,4 +151,14 @@ private function getAttributesHtml()

return $attributesHtml;
}

/**
* Get current page path info
*
* @return string
*/
private function getPathInfo()
{
return trim($this->_request->getPathInfo(), '/');
}
}

0 comments on commit 29640f1

Please sign in to comment.