Leuchtfeuer / locate

The users country and preferred language and other facts will be detected. Depending on configurable rules the user can be redirected to other languages or pages. New functionality can be added easily.
https://www.Leuchtfeuer.com
GNU General Public License v2.0
9 stars 14 forks source link

Reading frontend typoscript settings with BackendConfigurationManager in LanguageRedirectMiddleware #54

Open bigahuna opened 2 months ago

bigahuna commented 2 months ago

Describe the bug

Leuchtfeuer\Locate\Middleware\LanguageRedirectMiddleware reads typoscript settings like this $typoScript = $this->backendConfigurationManager->getTypoScriptSetup();

Reading typoscript frontend settings with the backendConfigurationManager results in unexpected behaviour with typoscript like this:

[traverse(page, "uid") in [968,967,202,965,969]]
    config.tx_locate = 0
[ELSE]
    config.tx_locate = 1
[GLOBAL]

The condition if (isset($typoScript['config.']['tx_locate']) && (int)$typoScript['config.']['tx_locate'] === 1) {} in LanguageRedirectMiddleware always returns true (config.tx_locate will always be 1), no matter what typoscript settings are configured. Maybe the reson is a changed behaviour in BackendConfigurationManager for TYPO3 v12. I did not dig deeper into this because there is a better, working solution:

If the typoscript setting will be read with the normal ConfigurationManager like this, it works just fine again:

/** @var ConfigurationManager $configurationManager */
$configurationManager = GeneralUtility::makeInstance(ConfigurationManager::class);
$typoScript = $configurationManager->getConfiguration(
ConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT,
    'sitepackage'
);

As far as I see, the BackendConfigurationManager is not really supposed to read frontend typoscript code anyway. See comment at the start of the class:

/*
* Load TypoScript of a page in backend mode.
*
* Extbase Backend modules can be configured with Frontend TypoScript. This is of course a very
* bad thing, but it is how it is ^^ (we'll get rid of this at some point, promised!)
*/

To Reproduce Steps to reproduce the behavior: Try to read fronten typoscript settings with the BackendConfigurationManager in Leuchtfeuer\Locate\Middleware\LanguageRedirectMiddleware

I hope I did not miss anything an will create a pull request.

Regards and thanks for a great and usefull extension!! Mike