builder = $builder; $this->msgLocalizer = $messageLocalizer; $this->specialPageFactory = $specialPageFactory; } /** * Returns a data representation of the main menus * @return array */ public function getMenuData(): array { if ( $this->menuData === null ) { $this->menuData = $this->buildMenu(); } return $this->menuData; } /** * Build the menu data array that can be passed to views/javascript * @return array */ private function buildMenu(): array { $menuData = [ 'buttonHTML' => $this->prepareToggle(), 'items' => [ 'groups' => [], 'sitelinks' => $this->builder->getSiteLinks()->getEntries() ] ]; foreach ( $this->builder->getGroups() as $group ) { if ( $group->hasEntries() ) { $menuData['items']['groups'][] = $group->getEntries(); } } return $menuData; } /** * Prepare the button opens the main side menu * @return string Rendered Menu button as HTML */ protected function prepareToggle() { $url = $this->specialPageFactory->exists( 'MobileMenu' ) ? SpecialPage::getTitleFor( 'MobileMenu' )->getLocalURL() : '#'; $title = $this->msgLocalizer->msg( 'mobile-frontend-main-menu-button-tooltip' )->text(); $tooltip = $this->msgLocalizer->msg( 'mobile-frontend-main-menu-button-tooltip' ) ->text(); return Html::element( 'a', [ 'title' => $title, 'href' => $url, 'class' => MinervaUI::iconClass( 'mainmenu', 'element', 'main-menu-button mw-ui-icon-flush-left' ), 'data-event-name' => 'ui.mainmenu', 'id' => 'mw-mf-main-menu-button', ], $tooltip ); } }