#90429ConfigurationManager should offer a way to define the site it is fetching a configuration for
Description
I have a multi-site setup in 9 LTS and I am doing the following in a Symfony console command:
$siteFinder = $objectManager->get(SiteFinder::class);
$site = $siteFinder->getSiteByIdentifier($input->getArgument('site'));
$objectManager = GeneralUtility::makeInstance(ObjectManager::class);
$configurationManager = $objectManager->get(ConfigurationManagerInterface::class);
$contentObjectRenderer = $objectManager->get(ContentObjectRenderer::class);
$configurationManager->setContentObject($contentObjectRenderer);
$settings = $configurationManager->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT);
Doing this, the ConfigurationManager always returns the configuration for the root page of the first site it finds in the page tree, as the following code at https://github.com/TYPO3/TYPO3.CMS/blob/9.5/typo3/sysext/extbase/Classes/Configuration/BackendConfigurationManager.php#L158 does not handle the current site:
protected function getCurrentPageIdFromCurrentSiteRoot()
{
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
->getQueryBuilderForTable('pages');
$queryBuilder
->getRestrictions()
->removeAll()
->add(GeneralUtility::makeInstance(DeletedRestriction::class))
->add(GeneralUtility::makeInstance(HiddenRestriction::class));
$rootPage = $queryBuilder
->select('uid')
->from('pages')
->where(
$queryBuilder->expr()->eq('is_siteroot', $queryBuilder->createNamedParameter(1, \PDO::PARAM_INT))
)
->orderBy('sorting')
->execute()
->fetch();
if (empty($rootPage)) {
return 0;
}
return (int)$rootPage['uid'];
}
**Also affected:**
There is no other place where $this->currentPageId gets set than in https://github.com/TYPO3/TYPO3.CMS/blob/9.5/typo3/sysext/extbase/Classes/Configuration/BackendConfigurationManager.php#L130, so $this->currentPageId is only available in a second call of this function:
protected function getCurrentPageId()
{
if ($this->currentPageId !== null) {
return $this->currentPageId;
}
$this->currentPageId = $this->getCurrentPageIdFromGetPostData() ?: $this->getCurrentPageIdFromCurrentSiteRoot();
$this->currentPageId = $this->currentPageId ?: $this->getCurrentPageIdFromRootTemplate();
$this->currentPageId = $this->currentPageId ?: self::DEFAULT_BACKEND_STORAGE_PID;
return $this->currentPageId;
}
At the moment I succeeded with the workaround of faking the current page id in my console command like this:
$siteFinder = $objectManager->get(SiteFinder::class);
$site = $siteFinder->getSiteByIdentifier($input->getArgument('site'));
if (!isset($_GET)) {
$_GET = [];
}
$_GET['id'] = $site->getRootPageId();
$objectManager = GeneralUtility::makeInstance(ObjectManager::class);
$configurationManager = $objectManager->get(ConfigurationManagerInterface::class);
$contentObjectRenderer = $objectManager->get(ContentObjectRenderer::class);
$configurationManager->setContentObject($contentObjectRenderer);
$settings = $configurationManager->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT);
This is, however, a quite dirty workaround. A quick fix would be to offer a setter for $this->currentPageId. However, maybe it would be better to offer a setter for the current site and from that fallback to the site’s $rootPageId if no $currentPageId is set.
Reviews 0
No change resolves or names this issue in its commit message, and no comment links one.