From 97c60ea9ce6ec59758f79a4c9924355c86df7c8a Mon Sep 17 00:00:00 2001 From: chris Date: Wed, 30 Mar 2022 15:25:43 +0200 Subject: [PATCH] [FEATURE] get root page id with SiteFinder, so multisite is possible --- Classes/Service/SettingsService.php | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/Classes/Service/SettingsService.php b/Classes/Service/SettingsService.php index 59d9460..250611b 100644 --- a/Classes/Service/SettingsService.php +++ b/Classes/Service/SettingsService.php @@ -14,6 +14,7 @@ * */ +use TYPO3\CMS\Core\Site\SiteFinder; use TYPO3\CMS\Core\TypoScript\TemplateService; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Core\Utility\RootlineUtility; @@ -36,7 +37,7 @@ public function getSettings(): array { // Backend mode, no TSFE loaded if (!isset($GLOBALS['TSFE'])) { - $typoScriptSetup = $this->getTypoScriptSetup(1); + $typoScriptSetup = $this->getTypoScriptSetup($this->getRootPageId()); $settings = $typoScriptSetup['plugin']['tx_mdsaml']['settings']; } else { /** @var ConfigurationManager $configurationManager */ @@ -87,6 +88,28 @@ function (&$value) { return $settings; } + /** + * Get root page ID according to calling url + * + * @return int|null + */ + private function getRootPageId(): ?int + { + $siteUrl = GeneralUtility::getIndpEnv('TYPO3_HOST_ONLY'); + + $siteFinder = GeneralUtility::makeInstance(SiteFinder::class); + $allsites = $siteFinder->getAllSites(); + + /** @var \TYPO3\CMS\Core\Site\Entity\Site $site */ + foreach ($allsites as $site) { + if ($site->getBase()->getHost() == $siteUrl) { + return $site->getRootPageId(); + } + } + + throw new \RuntimeException('The site configuration could not be resolved.', 1648646492); + } + /** * Get TypoScript setup *