Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields | Protected Member Functions | Protected Attributes
Menu Class Reference
Inheritance diagram for Menu:
Template Template AbstractBlock DataObject BlockInterface

Public Member Functions

 __construct (\Magento\Backend\Block\Template\Context $context, \Magento\Backend\Model\UrlInterface $url, \Magento\Backend\Model\Menu\Filter\IteratorFactory $iteratorFactory, \Magento\Backend\Model\Auth\Session $authSession, \Magento\Backend\Model\Menu\Config $menuConfig, \Magento\Framework\Locale\ResolverInterface $localeResolver, array $data=[], MenuItemChecker $menuItemChecker=null, AnchorRenderer $anchorRenderer=null, \Magento\Framework\App\Route\ConfigInterface $routeConfig=null)
 
 getCacheLifetime ()
 
 getCacheKeyInfo ()
 
 getMenuModel ()
 
 getActiveItemModel ()
 
- Public Member Functions inherited from Template
 __construct (\Magento\Backend\Block\Template\Context $context, array $data=[])
 
 getFormKey ()
 
 isOutputEnabled ($moduleName=null)
 
 getAuthorization ()
 
 getToolbar ()
 
- Public Member Functions inherited from Template
 __construct (Template\Context $context, array $data=[])
 
 setTemplateContext ($templateContext)
 
 getTemplate ()
 
 setTemplate ($template)
 
 getTemplateFile ($template=null)
 
 getArea ()
 
 assign ($key, $value=null)
 
 fetchView ($fileName)
 
 getBaseUrl ()
 
 getObjectData (\Magento\Framework\DataObject $object, $key)
 
 getCacheKeyInfo ()
 
- Public Member Functions inherited from AbstractBlock
 __construct (\Magento\Framework\View\Element\Context $context, array $data=[])
 
 getJsLayout ()
 
 getRequest ()
 
 getParentBlock ()
 
 setLayout (\Magento\Framework\View\LayoutInterface $layout)
 
 getLayout ()
 
 setNameInLayout ($name)
 
 getChildNames ()
 
 setAttribute ($name, $value=null)
 
 setChild ($alias, $block)
 
 addChild ($alias, $block, $data=[])
 
 unsetChild ($alias)
 
 unsetCallChild ($alias, $callback, $result, $params)
 
 unsetChildren ()
 
 getChildBlock ($alias)
 
 getChildHtml ($alias='', $useCache=true)
 
 getChildChildHtml ($alias, $childChildAlias='', $useCache=true)
 
 getBlockHtml ($name)
 
 insert ($element, $siblingName=0, $after=true, $alias='')
 
 append ($element, $alias='')
 
 getGroupChildNames ($groupName)
 
 getChildData ($alias, $key='')
 
 getUiId ($arg1=null, $arg2=null, $arg3=null, $arg4=null, $arg5=null)
 
 getJsId ($arg1=null, $arg2=null, $arg3=null, $arg4=null, $arg5=null)
 
 getUrl ($route='', $params=[])
 
 getViewFileUrl ($fileId, array $params=[])
 
 formatDate ( $date=null, $format=\IntlDateFormatter::SHORT, $showTime=false, $timezone=null)
 
 formatTime ( $time=null, $format=\IntlDateFormatter::SHORT, $showDate=false)
 
 getModuleName ()
 
 escapeHtml ($data, $allowedTags=null)
 
 escapeJs ($string)
 
 escapeHtmlAttr ($string, $escapeSingleQuote=true)
 
 escapeCss ($string)
 
 stripTags ($data, $allowableTags=null, $allowHtmlEntities=false)
 
 escapeUrl ($string)
 
 escapeXssInUrl ($data)
 
 escapeQuote ($data, $addSlashes=false)
 
 escapeJsQuote ($data, $quote='\'')
 
 getNameInLayout ()
 
 getCacheKeyInfo ()
 
 getCacheKey ()
 
 getVar ($name, $module=null)
 
 isScopePrivate ()
 
- Public Member Functions inherited from DataObject
 __construct (array $data=[])
 
 addData (array $arr)
 
 setData ($key, $value=null)
 
 unsetData ($key=null)
 
 getData ($key='', $index=null)
 
 getDataByPath ($path)
 
 getDataByKey ($key)
 
 setDataUsingMethod ($key, $args=[])
 
 getDataUsingMethod ($key, $args=null)
 
 hasData ($key='')
 
 toArray (array $keys=[])
 
 convertToArray (array $keys=[])
 
 toXml (array $keys=[], $rootName='item', $addOpenTag=false, $addCdata=true)
 
 convertToXml (array $arrAttributes=[], $rootName='item', $addOpenTag=false, $addCdata=true)
 
 toJson (array $keys=[])
 
 convertToJson (array $keys=[])
 
 toString ($format='')
 
 __call ($method, $args)
 
 isEmpty ()
 
 serialize ($keys=[], $valueSeparator='=', $fieldSeparator=' ', $quote='"')
 
 debug ($data=null, &$objects=[])
 
 offsetSet ($offset, $value)
 
 offsetExists ($offset)
 
 offsetUnset ($offset)
 
 offsetGet ($offset)
 
- Public Member Functions inherited from BlockInterface
 toHtml ()
 

Data Fields

const CACHE_TAGS = 'BACKEND_MAINMENU'
 
- Data Fields inherited from Template
const XML_PATH_TEMPLATE_ALLOW_SYMLINK = 'dev/template/allow_symlink'
 
- Data Fields inherited from AbstractBlock
const CACHE_GROUP = \Magento\Framework\App\Cache\Type\Block::TYPE_IDENTIFIER
 
const CACHE_KEY_PREFIX = 'BLOCK_'
 

Protected Member Functions

 _construct ()
 
 _getAnchorLabel ($menuItem)
 
 _renderMouseEvent ($menuItem)
 
 _renderItemCssClass ($menuItem, $level)
 
 _getMenuIterator ($menu)
 
 _afterToHtml ($html)
 
 _callbackSecretKey ($match)
 
 _columnBrake ($items, $limit)
 
 _addSubMenu ($menuItem, $level, $limit, $id=null)
 
- Protected Member Functions inherited from Template
 _toHtml ()
 
- Protected Member Functions inherited from Template
 _construct ()
 
 _toHtml ()
 
 getRootDirectory ()
 
 getMediaDirectory ()
 
- Protected Member Functions inherited from AbstractBlock
 _construct ()
 
 _prepareLayout ()
 
 _beforeToHtml ()
 
 _afterToHtml ($html)
 
 _toHtml ()
 
 _getNotFoundUrl ($route='', $params=['_direct'=> 'core/index/notFound'])
 
 getCacheTags ()
 
 getCacheLifetime ()
 
 _loadCache ()
 
 _saveCache ($data)
 
 _getSidPlaceholder ($cacheKey=null)
 
- Protected Member Functions inherited from DataObject
 _getData ($key)
 
 _underscore ($name)
 

Protected Attributes

 $_containerRenderer
 
 $_itemRenderer
 
 $_url
 
 $_activeItemModel = null
 
 $_iteratorFactory
 
 $_authSession
 
 $_menuConfig
 
 $_localeResolver
 
- Protected Attributes inherited from Template
 $_authorization
 
 $mathRandom
 
 $_backendSession
 
 $formKey
 
 $nameBuilder
 
- Protected Attributes inherited from Template
 $_viewVars = []
 
 $_baseUrl
 
 $_jsUrl
 
 $_allowSymlinks
 
 $_filesystem
 
 $_template
 
 $templateEnginePool
 
 $_storeManager
 
 $_appState
 
 $directory
 
 $templateContext
 
 $pageConfig
 
 $resolver
 
 $validator
 
- Protected Attributes inherited from AbstractBlock
 $_design
 
 $_session
 
 $_sidResolver
 
 $_nameInLayout
 
 $_layout
 
 $jsLayout = []
 
 $_request
 
 $_urlBuilder
 
 $_eventManager
 
 $_frontController
 
 $_assetRepo
 
 $_viewConfig
 
 $_cacheState
 
 $_logger
 
 $_escaper
 
 $filterManager
 
 $_localeDate
 
 $inlineTranslation
 
 $_isScopePrivate = false
 
 $_scopeConfig
 
 $_cache
 
- Protected Attributes inherited from DataObject
 $_data = []
 

Additional Inherited Members

- Static Public Member Functions inherited from AbstractBlock
static extractModuleName ($className)
 
- Static Protected Attributes inherited from DataObject
static $_underscoreCache = []
 

Detailed Description

Backend menu block

@method $this setAdditionalCacheKeyInfo(array $cacheKeyInfo) @method array getAdditionalCacheKeyInfo() @api

Since
100.0.2

@SuppressWarnings(PHPMD.CouplingBetweenObjects)

Definition at line 19 of file Menu.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( \Magento\Backend\Block\Template\Context  $context,
\Magento\Backend\Model\UrlInterface  $url,
\Magento\Backend\Model\Menu\Filter\IteratorFactory  $iteratorFactory,
\Magento\Backend\Model\Auth\Session  $authSession,
\Magento\Backend\Model\Menu\Config  $menuConfig,
\Magento\Framework\Locale\ResolverInterface  $localeResolver,
array  $data = [],
MenuItemChecker  $menuItemChecker = null,
AnchorRenderer  $anchorRenderer = null,
\Magento\Framework\App\Route\ConfigInterface  $routeConfig = null 
)
Parameters
\Magento\Backend\Block\Template\Context$context
\Magento\Backend\Model\UrlInterface$url
\Magento\Backend\Model\Menu\Filter\IteratorFactory$iteratorFactory
\Magento\Backend\Model\Auth\Session$authSession
\Magento\Backend\Model\Menu\Config$menuConfig
\Magento\Framework\Locale\ResolverInterface$localeResolver
array$data
MenuItemChecker | null$menuItemChecker
AnchorRenderer | null$anchorRenderer
\Magento\Framework\App\Route\ConfigInterface | null$routeConfig@SuppressWarnings(PHPMD.ExcessiveParameterList)

Definition at line 96 of file Menu.php.

107  {
108  $this->_url = $url;
109  $this->_iteratorFactory = $iteratorFactory;
110  $this->_authSession = $authSession;
111  $this->_menuConfig = $menuConfig;
112  $this->_localeResolver = $localeResolver;
113  $this->menuItemChecker = $menuItemChecker;
114  $this->anchorRenderer = $anchorRenderer;
115  $this->routeConfig = $routeConfig ?:
117  ->get(\Magento\Framework\App\Route\ConfigInterface::class);
118  parent::__construct($context, $data);
119  }

Member Function Documentation

◆ _addSubMenu()

_addSubMenu (   $menuItem,
  $level,
  $limit,
  $id = null 
)
protected

Add sub menu HTML code for current menu item

Parameters
\Magento\Backend\Model\Menu\Item$menuItem
int$level
int$limit
int | null$id
Returns
string HTML code

Definition at line 362 of file Menu.php.

363  {
364  $output = '';
365  if (!$menuItem->hasChildren()) {
366  return $output;
367  }
368  $output .= '<div class="submenu"' . ($level == 0 && isset($id) ? ' aria-labelledby="' . $id . '"' : '') . '>';
369  $colStops = [];
370  if ($level == 0 && $limit) {
371  $colStops = $this->_columnBrake($menuItem->getChildren(), $limit);
372  $output .= '<strong class="submenu-title">' . $this->_getAnchorLabel($menuItem) . '</strong>';
373  $output .= '<a href="#" class="action-close _close" data-role="close-submenu"></a>';
374  }
375 
376  $output .= $this->renderNavigation($menuItem->getChildren(), $level + 1, $limit, $colStops);
377  $output .= '</div>';
378  return $output;
379  }
$id
Definition: fieldset.phtml:14
_columnBrake($items, $limit)
Definition: Menu.php:328
_getAnchorLabel($menuItem)
Definition: Menu.php:138

◆ _afterToHtml()

_afterToHtml (   $html)
protected

Processing block html after rendering

Parameters
string$html
Returns
string

Definition at line 200 of file Menu.php.

201  {
202  $html = preg_replace_callback(
203  '#' . \Magento\Backend\Model\UrlInterface::SECRET_KEY_PARAM_NAME . '/\$([^\/].*)/([^\/].*)/([^\$].*)\$#U',
204  [$this, '_callbackSecretKey'],
205  $html
206  );
207 
208  return $html;
209  }

◆ _callbackSecretKey()

_callbackSecretKey (   $match)
protected

Replace Callback Secret Key

Parameters
string[]$match
Returns
string

Definition at line 217 of file Menu.php.

218  {
219  $routeId = $this->routeConfig->getRouteByFrontName($match[1]);
220  return \Magento\Backend\Model\UrlInterface::SECRET_KEY_PARAM_NAME . '/' . $this->_url->getSecretKey(
221  $routeId ?: $match[1],
222  $match[2],
223  $match[3]
224  );
225  }

◆ _columnBrake()

_columnBrake (   $items,
  $limit 
)
protected

Building Array with Column Brake Stops

Parameters
\Magento\Backend\Model\Menu$items
int$limit
Returns
array|void
Todo:
: Add Depth Level limit, and better logic for columns

Definition at line 328 of file Menu.php.

329  {
330  $total = $this->_countItems($items);
331  if ($total <= $limit) {
332  return;
333  }
334  $result[] = ['total' => $total, 'max' => ceil($total / ceil($total / $limit))];
335  $count = 0;
336  foreach ($items as $item) {
337  $place = $this->_countItems($item->getChildren()) + 1;
338  $count += $place;
339  if ($place - $result[0]['max'] > $limit - $result[0]['max']) {
340  $colbrake = true;
341  $count = 0;
342  } elseif ($count - $result[0]['max'] > $limit - $result[0]['max']) {
343  $colbrake = true;
344  $count = $place;
345  } else {
346  $colbrake = false;
347  }
348  $result[] = ['place' => $place, 'colbrake' => $colbrake];
349  }
350  return $result;
351  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
$count
Definition: recent.phtml:13
$items

◆ _construct()

_construct ( )
protected

Initialize template and cache settings

Returns
void

Definition at line 126 of file Menu.php.

127  {
128  parent::_construct();
129  $this->setCacheTags([self::CACHE_TAGS]);
130  }

◆ _getAnchorLabel()

_getAnchorLabel (   $menuItem)
protected

Render menu item anchor label

Parameters
\Magento\Backend\Model\Menu\Item$menuItem
Returns
string

Definition at line 138 of file Menu.php.

139  {
140  return $this->escapeHtml(__($menuItem->getTitle()));
141  }
__()
Definition: __.php:13

◆ _getMenuIterator()

_getMenuIterator (   $menu)
protected

Get menu filter iterator

Parameters
\Magento\Backend\Model\Menu$menu
Returns
\Magento\Backend\Model\Menu\Filter\Iterator

Definition at line 189 of file Menu.php.

190  {
191  return $this->_iteratorFactory->create(['iterator' => $menu->getIterator()]);
192  }

◆ _renderItemCssClass()

_renderItemCssClass (   $menuItem,
  $level 
)
protected

Render item css class

Parameters
\Magento\Backend\Model\Menu\Item$menuItem
int$level
Returns
string

Definition at line 163 of file Menu.php.

164  {
165  $isLast = 0 == $level && (bool)$this->getMenuModel()->isLast($menuItem) ? 'last' : '';
166  $isItemActive = $this->menuItemChecker->isItemActive(
167  $this->getActiveItemModel(),
168  $menuItem,
169  $level
170  ) ? '_current _active' : '';
171 
172  $output = $isItemActive .
173  ' ' .
174  ($menuItem->hasChildren() ? 'parent' : '') .
175  ' ' .
176  $isLast .
177  ' ' .
178  'level-' .
179  $level;
180  return $output;
181  }

◆ _renderMouseEvent()

_renderMouseEvent (   $menuItem)
protected

Render menu item mouse events

Parameters
\Magento\Backend\Model\Menu\Item$menuItem
Returns
string

Definition at line 149 of file Menu.php.

150  {
151  return $menuItem->hasChildren()
152  ? 'onmouseover="Element.addClassName(this,\'over\')" onmouseout="Element.removeClassName(this,\'over\')"'
153  : '';
154  }

◆ getActiveItemModel()

getActiveItemModel ( )

Get current selected menu item

Returns
\Magento\Backend\Model\Menu\Item|false

Definition at line 434 of file Menu.php.

435  {
436  if ($this->_activeItemModel === null) {
437  $this->_activeItemModel = $this->getMenuModel()->get($this->getActive());
438  if (false == $this->_activeItemModel instanceof \Magento\Backend\Model\Menu\Item) {
439  $this->_activeItemModel = false;
440  }
441  }
443  }

◆ getCacheKeyInfo()

getCacheKeyInfo ( )

Get Key pieces for caching block content

Returns
array

Definition at line 242 of file Menu.php.

243  {
244  $cacheKeyInfo = [
245  'admin_top_nav',
246  $this->getActive(),
247  $this->_authSession->getUser()->getId(),
248  $this->_localeResolver->getLocale(),
249  ];
250  // Add additional key parameters if needed
251  $newCacheKeyInfo = $this->getAdditionalCacheKeyInfo();
252  if (is_array($newCacheKeyInfo) && !empty($newCacheKeyInfo)) {
253  $cacheKeyInfo = array_merge($cacheKeyInfo, $newCacheKeyInfo);
254  }
255  return $cacheKeyInfo;
256  }

◆ getCacheLifetime()

getCacheLifetime ( )

Retrieve cache lifetime

Returns
int

Definition at line 232 of file Menu.php.

233  {
234  return 86400;
235  }

◆ getMenuModel()

getMenuModel ( )

Get menu config model

Returns
\Magento\Backend\Model\Menu

Definition at line 263 of file Menu.php.

264  {
265  return $this->_menuConfig->getMenu();
266  }

Field Documentation

◆ $_activeItemModel

$_activeItemModel = null
protected

Definition at line 45 of file Menu.php.

◆ $_authSession

$_authSession
protected

Definition at line 55 of file Menu.php.

◆ $_containerRenderer

$_containerRenderer
protected

Definition at line 26 of file Menu.php.

◆ $_itemRenderer

$_itemRenderer
protected

Definition at line 31 of file Menu.php.

◆ $_iteratorFactory

$_iteratorFactory
protected

Definition at line 50 of file Menu.php.

◆ $_localeResolver

$_localeResolver
protected

Definition at line 65 of file Menu.php.

◆ $_menuConfig

$_menuConfig
protected

Definition at line 60 of file Menu.php.

◆ $_url

$_url
protected

Definition at line 38 of file Menu.php.

◆ CACHE_TAGS

const CACHE_TAGS = 'BACKEND_MAINMENU'

Definition at line 21 of file Menu.php.


The documentation for this class was generated from the following file: