/**
  * Builds NavigationItem's from given root pages.
  *
  * @param PageModel[] $rootPages
  *
  * @return NavigationItem[]
  *
  * @throws \RuntimeException if multiple root pages have the same language
  */
 private function createNavigationItemsForRootPages(array $rootPages)
 {
     $navigationItems = [];
     foreach ($rootPages as $rootPage) {
         if (!$this->isPagePublished($rootPage)) {
             continue;
         }
         $language = strtolower($rootPage->language);
         if (array_key_exists($language, $navigationItems)) {
             throw new \RuntimeException(sprintf('Multiple root pages for the language "%s" found', $rootPage->language));
         }
         $navigationItems[$language] = new NavigationItem($rootPage, $this->languageText->get($language));
     }
     return $navigationItems;
 }
 /**
  * @inheritdoc
  */
 protected function compile()
 {
     $currentPage = $this->getCurrentPage();
     $pageFinder = new PageFinder();
     if ($this->customLanguage) {
         $languageText = LanguageText::createFromOptionWizard($this->customLanguageText);
     } else {
         $languageText = new LanguageText();
     }
     $navigationFactory = new NavigationFactory($pageFinder, $languageText, $currentPage);
     $navigationItems = $navigationFactory->findNavigationItems($currentPage);
     // Do not generate module or header if there is none or only one link
     if (count($navigationItems) < 2) {
         return;
     }
     $templateItems = [];
     $headerLinks = new AlternateLinks();
     $queryParameters = $currentPage->languageQuery ? trimsplit(',', $currentPage->languageQuery) : [];
     $defaultUrlParameters = $this->createUrlParameterBag($queryParameters);
     foreach ($navigationItems as $item) {
         $urlParameters = clone $defaultUrlParameters;
         if (false === $this->executeHook($item, $urlParameters) || $this->hideNoFallback && !$item->isDirectFallback()) {
             continue;
         }
         if ($item->isDirectFallback()) {
             $headerLinks->addFromNavigationItem($item, $urlParameters);
         }
         // Remove active language from navigation but not from header links!
         if ($this->hideActiveLanguage && $item->isCurrentPage()) {
             continue;
         }
         $templateItems[] = $this->generateTemplateArray($item, $urlParameters);
     }
     $this->Template->items = $this->generateNavigationTemplate($templateItems);
     $GLOBALS['TL_HEAD'][] = $headerLinks->generate();
 }