-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #799 from magento-firedrakes/MAGETWO-63716
[Firedrakes] Add target to admin menu element
- Loading branch information
Showing
20 changed files
with
907 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
<?php | ||
/** | ||
* Copyright © 2013-2017 Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\Backend\Block; | ||
|
||
use Magento\Backend\Model\Menu\Item; | ||
use Magento\Framework\Escaper; | ||
|
||
/** | ||
* Class AnchorRenderer | ||
*/ | ||
class AnchorRenderer | ||
{ | ||
/** | ||
* @var MenuItemChecker | ||
*/ | ||
private $menuItemChecker; | ||
|
||
/** | ||
* @var Escaper | ||
*/ | ||
private $escaper; | ||
|
||
/** | ||
* @param MenuItemChecker $menuItemChecker | ||
* @param Escaper $escaper | ||
*/ | ||
public function __construct( | ||
MenuItemChecker $menuItemChecker, | ||
Escaper $escaper | ||
) { | ||
$this->menuItemChecker = $menuItemChecker; | ||
$this->escaper = $escaper; | ||
} | ||
|
||
/** | ||
* Render menu item anchor. | ||
* | ||
* It is used in backend menu to render anchor menu. | ||
* | ||
* @param Item|false $activeItem Can be false if menu item is inaccessible | ||
* but was triggered directly using controller. It is a legacy code behaviour. | ||
* @param Item $menuItem | ||
* @param int $level | ||
* @return string | ||
*/ | ||
public function renderAnchor($activeItem, Item $menuItem, $level) | ||
{ | ||
if ($level == 1 && $menuItem->getUrl() == '#') { | ||
$output = '<strong class="submenu-group-title" role="presentation">' | ||
. '<span>' . $this->escaper->escapeHtml(__($menuItem->getTitle())) . '</span>' | ||
. '</strong>'; | ||
} else { | ||
$target = $menuItem->getTarget() ? ('target=' . $menuItem->getTarget()) : ''; | ||
$output = '<a href="' . $menuItem->getUrl() . '" ' . $target . ' ' . $this->_renderItemAnchorTitle( | ||
$menuItem | ||
) . $this->_renderItemOnclickFunction( | ||
$menuItem | ||
) . ' class="' . ($this->menuItemChecker->isItemActive($activeItem, $menuItem, $level) ? '_active' : '') | ||
. '">' . '<span>' . $this->escaper->escapeHtml(__($menuItem->getTitle())) | ||
. '</span>' . '</a>'; | ||
} | ||
|
||
return $output; | ||
} | ||
|
||
/** | ||
* Render menu item anchor title | ||
* | ||
* @param Item $menuItem | ||
* @return string | ||
*/ | ||
private function _renderItemAnchorTitle($menuItem) | ||
{ | ||
return $menuItem->hasTooltip() ? 'title="' . __($menuItem->getTooltip()) . '"' : ''; | ||
} | ||
|
||
/** | ||
* Render menu item onclick function | ||
* | ||
* @param Item $menuItem | ||
* @return string | ||
*/ | ||
private function _renderItemOnclickFunction($menuItem) | ||
{ | ||
return $menuItem->hasClickCallback() ? ' onclick="' . $menuItem->getClickCallback() . '"' : ''; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
/** | ||
* Copyright © 2013-2017 Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\Backend\Block; | ||
|
||
use Magento\Backend\Model\Menu\Item; | ||
|
||
/** | ||
* Class MenuItemChecker | ||
*/ | ||
class MenuItemChecker | ||
{ | ||
/** | ||
* Check whether given menu item is currently selected. | ||
* | ||
* It is used in backend menu to highlight active menu item. | ||
* | ||
* @param Item|false $activeItem Can be false if menu item is inaccessible | ||
* but was triggered directly using controller. It is a legacy code behaviour. | ||
* @param Item $item | ||
* @param int $level | ||
* @return bool | ||
*/ | ||
public function isItemActive($activeItem, Item $item, $level) | ||
{ | ||
$output = false; | ||
|
||
if ($level == 0 | ||
&& $activeItem instanceof \Magento\Backend\Model\Menu\Item | ||
&& $this->isActiveItemEqualOrChild($activeItem, $item) | ||
) { | ||
$output = true; | ||
} | ||
return $output; | ||
} | ||
|
||
/** | ||
* @param Item $activeItem, | ||
* @param Item $item | ||
* @return bool | ||
*/ | ||
private function isActiveItemEqualOrChild($activeItem, $item) | ||
{ | ||
return ($activeItem->getId() == $item->getId()) | ||
|| ($item->getChildren()->get($activeItem->getId()) !== null); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.