/** * Get Menu model * * @return \Magento\Backend\Model\Menu */ protected function _getMenu() { if ($this->_menu === null) { $this->_menu = $this->_menuConfig->getMenu(); } return $this->_menu; }
public function testGetMenuGenericExceptionIsNotLogged() { $this->_logger->expects($this->never())->method('critical'); $this->_menuBuilderMock->expects($this->exactly(1))->method('getResult')->will($this->throwException(new \Exception())); try { $this->_model->getMenu(); } catch (\Exception $e) { return; } $this->fail("Generic \\Exception was not throwed"); }
/** * Convert xml config paths to decorated names * * @param array $paths * @return array * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ protected function _getSystemConfigPathsParts($paths) { $result = $urlParams = $prefixParts = []; $scopeLabel = __('Default Config'); if ($paths) { /** @var $menu \Magento\Backend\Model\Menu */ $menu = $this->_menuConfig->getMenu(); $item = $menu->get('Magento_Backend::stores'); // create prefix path parts $prefixParts[] = ['title' => __($item->getTitle())]; $item = $menu->get('Magento_Config::system_config'); $prefixParts[] = ['title' => __($item->getTitle()), 'url' => $this->getUrl('adminhtml/system_config/')]; $pathParts = $prefixParts; foreach ($paths as $pathData) { $pathDataParts = explode('/', $pathData['path']); $sectionName = array_shift($pathDataParts); $urlParams = ['section' => $sectionName]; if (isset($pathData['scope']) && isset($pathData['scope_id'])) { switch ($pathData['scope']) { case 'stores': $store = $this->_storeManager->getStore($pathData['scope_id']); if ($store) { $urlParams['website'] = $store->getWebsite()->getCode(); $urlParams['store'] = $store->getCode(); $scopeLabel = $store->getWebsite()->getName() . '/' . $store->getName(); } break; case 'websites': $website = $this->_storeManager->getWebsite($pathData['scope_id']); if ($website) { $urlParams['website'] = $website->getCode(); $scopeLabel = $website->getName(); } break; default: break; } } $pathParts[] = ['title' => $this->_configStructure->getElement($sectionName)->getLabel(), 'url' => $this->getUrl('adminhtml/system_config/edit', $urlParams)]; $elementPathParts = [$sectionName]; while (count($pathDataParts) != 1) { $elementPathParts[] = array_shift($pathDataParts); $pathParts[] = ['title' => $this->_configStructure->getElementByPathParts($elementPathParts)->getLabel()]; } $elementPathParts[] = array_shift($pathDataParts); $pathParts[] = ['title' => $this->_configStructure->getElementByPathParts($elementPathParts)->getLabel(), 'scope' => $scopeLabel]; $result[] = $pathParts; $pathParts = $prefixParts; } } return $result; }
/** * Get menu config model * * @return \Magento\Backend\Model\Menu */ public function getMenuModel() { return $this->_menuConfig->getMenu(); }
/** * @param \Magento\Backend\Model\Menu\Filter\IteratorFactory $iteratorFactory * @param \Magento\Backend\Model\Menu\Config $menuConfig */ public function __construct(\Magento\Backend\Model\Menu\Filter\IteratorFactory $iteratorFactory, \Magento\Backend\Model\Menu\Config $menuConfig) { $this->_menu = $menuConfig->getMenu(); $this->_iteratorFactory = $iteratorFactory; }