Skip to content

Commit

Permalink
[FEATURE] get root page id with SiteFinder, so multisite is possible
Browse files Browse the repository at this point in the history
  • Loading branch information
cdaecke committed Mar 30, 2022
1 parent 0bc7348 commit 97c60ea
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion Classes/Service/SettingsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 */
Expand Down Expand Up @@ -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
*
Expand Down

0 comments on commit 97c60ea

Please sign in to comment.