Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AnchorRenderer.php
Go to the documentation of this file.
1 <?php
6 namespace Magento\Backend\Block;
7 
10 
15 {
19  private $menuItemChecker;
20 
24  private $escaper;
25 
30  public function __construct(
31  MenuItemChecker $menuItemChecker,
32  Escaper $escaper
33  ) {
34  $this->menuItemChecker = $menuItemChecker;
35  $this->escaper = $escaper;
36  }
37 
49  public function renderAnchor($activeItem, Item $menuItem, $level)
50  {
51  if ($level == 1 && $menuItem->getUrl() == '#') {
52  $output = '';
53  if ($menuItem->hasChildren()) {
54  $output = '<strong class="submenu-group-title" role="presentation">'
55  . '<span>' . $this->escaper->escapeHtml(__($menuItem->getTitle())) . '</span>'
56  . '</strong>';
57  }
58  } else {
59  $target = $menuItem->getTarget() ? ('target=' . $menuItem->getTarget()) : '';
60  $output = '<a href="' . $menuItem->getUrl() . '" ' . $target . ' ' . $this->_renderItemAnchorTitle(
61  $menuItem
62  ) . $this->_renderItemOnclickFunction(
63  $menuItem
64  ) . ' class="' . ($this->menuItemChecker->isItemActive($activeItem, $menuItem, $level) ? '_active' : '')
65  . '">' . '<span>' . $this->escaper->escapeHtml(__($menuItem->getTitle()))
66  . '</span>' . '</a>';
67  }
68 
69  return $output;
70  }
71 
78  private function _renderItemAnchorTitle($menuItem)
79  {
80  return $menuItem->hasTooltip() ? 'title="' . __($menuItem->getTooltip()) . '"' : '';
81  }
82 
89  private function _renderItemOnclickFunction($menuItem)
90  {
91  return $menuItem->hasClickCallback() ? ' onclick="' . $menuItem->getClickCallback() . '"' : '';
92  }
93 }
$target
Definition: skip.phtml:8
__()
Definition: __.php:13
__construct(MenuItemChecker $menuItemChecker, Escaper $escaper)
renderAnchor($activeItem, Item $menuItem, $level)