builder = $builder; $this->msgLocalizer = $messageLocalizer; $this->specialPageFactory = $specialPageFactory; } /** * Returns a data representation of the main menus * * @param array $contentNavUrls result of buildContentNavigationUrls * @param array $sidebar * @return array */ public function getMenuData( array $contentNavUrls, array $sidebar ): array { if ( $this->menuData === null ) { $this->menuData = $this->buildMenu( $contentNavUrls, $sidebar ); } return $this->menuData; } /** * Build the menu data array that can be passed to views/javascript * * @param array $contentNavUrls * @param array $sidebar * @return array */ private function buildMenu( array $contentNavUrls, array $sidebar ): array { $builder = $this->builder; $menuData = [ 'items' => [ 'groups' => [], 'sitelinks' => $this->builder->getSiteLinks()->getEntries() ] ]; $groups = [ // sidebar comes from MediaWiki:Sidebar so we can't assume it doesn't exist. $builder->getDiscoveryGroup( $sidebar['navigation'] ?? [] ), $builder->getInteractionToolsGroup(), $builder->getPersonalToolsGroup( $contentNavUrls['user-menu'] ), $builder->getSettingsGroup(), $builder->getDonateGroup(), ]; foreach ( $groups as $group ) { if ( $group->hasEntries() ) { $menuData['items']['groups'][] = $group->serialize(); } } return $menuData; } }