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 = [ 'items' => [ 'groups' => [], 'sitelinks' => $this->builder->getSiteLinks()->getEntries() ] ]; foreach ( $this->builder->getGroups() as $group ) { if ( $group->hasEntries() ) { $menuData['items']['groups'][] = $group->serialize(); } } return $menuData; } }