languages[0] = new SiteLanguage( 0, '', new Uri('/'), ['enabled' => true] ); } else { foreach ($languages as $languageConfiguration) { $languageUid = (int)$languageConfiguration['languageId']; // Language configuration does not have a base defined // So the main site base is used (usually done for default languages) $this->languages[$languageUid] = new SiteLanguage( $languageUid, $languageConfiguration['locale'] ?? '', $baseEntryPoint ?: new Uri('/'), $languageConfiguration ); } } } /** * Returns always #NULL */ public function getIdentifier(): string { return '#NULL'; } /** * Always "/" */ public function getBase(): UriInterface { return new Uri('/'); } /** * Always zero */ public function getRootPageId(): int { return 0; } /** * Returns all available languages of this installation * * @return SiteLanguage[] */ public function getLanguages(): array { return $this->languages; } /** * Returns a language of this site, given by the sys_language_uid * * @throws \InvalidArgumentException */ public function getLanguageById(int $languageId): SiteLanguage { if (isset($this->languages[$languageId])) { return $this->languages[$languageId]; } throw new \InvalidArgumentException( 'Language ' . $languageId . ' does not exist on site ' . $this->getIdentifier() . '.', 1522965188 ); } public function getDefaultLanguage(): SiteLanguage { return reset($this->languages); } /** * This takes page TSconfig into account (unlike Site interface) to find * mod.SHARED.disableLanguages and mod.SHARED.defaultLanguageLabel */ public function getAvailableLanguages(BackendUserAuthentication $user, bool $includeAllLanguagesFlag = false, ?int $pageId = null): array { $availableLanguages = []; // Check if we need to add language "-1" if ($includeAllLanguagesFlag && $user->checkLanguageAccess(-1)) { $availableLanguages[-1] = new SiteLanguage(-1, '', $this->getBase(), [ 'title' => $this->getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_mod_web_list.xlf:multipleLanguages'), 'flag' => 'flags-multiple', ]); } $pageTs = BackendUtility::getPagesTSconfig((int)$pageId); $pageTs = $pageTs['mod.']['SHARED.'] ?? []; $disabledLanguages = GeneralUtility::intExplode(',', (string)($pageTs['disableLanguages'] ?? ''), true); // Do not add the ones that are not allowed by the user foreach ($this->languages as $language) { if ($user->checkLanguageAccess($language) && !in_array($language->getLanguageId(), $disabledLanguages, true)) { if ($language->getLanguageId() === 0) { // 0: "Default" language $defaultLanguageLabel = 'LLL:EXT:core/Resources/Private/Language/locallang_mod_web_list.xlf:defaultLanguage'; $defaultLanguageLabel = $this->getLanguageService()->sL($defaultLanguageLabel); if (isset($pageTs['defaultLanguageLabel'])) { $defaultLanguageLabel = $pageTs['defaultLanguageLabel'] . ' (' . $defaultLanguageLabel . ')'; } $defaultLanguageFlag = ''; if (isset($pageTs['defaultLanguageFlag'])) { $defaultLanguageFlag = 'flags-' . $pageTs['defaultLanguageFlag']; } $language = new SiteLanguage(0, '', $language->getBase(), [ 'title' => $defaultLanguageLabel, 'flag' => $defaultLanguageFlag, ]); } $availableLanguages[$language->getLanguageId()] = $language; } } return $availableLanguages; } /** * Returns a ready-to-use error handler, to be used within the ErrorController */ public function getErrorHandler(int $statusCode): PageErrorHandlerInterface { throw new \RuntimeException('No error handler given for the status code "' . $statusCode . '".', 1522495102); } protected function getLanguageService(): LanguageService { return $GLOBALS['LANG']; } }