Gregor-Agnes / newsletter_subscribe

TYPO3-extension: Subscribe and unsubscribe to tt_address, generate static Link to unsubscribe (to use in Newsletter), automatically delete unconfirmed subscribers
https://extensions.typo3.org/extension/newsletter_subscribe
GNU General Public License v3.0
2 stars 5 forks source link

prepareTwoLetterIsoCode() returns Code from TSFE but should take it from site config #90

Closed fischhase closed 1 week ago

fischhase commented 3 months ago

Hi Gregor, in TYPO3 12 the language code detection fails. It always returns 'de' but the default language is 'en'. Even by changing the language the output keeps 'de'.

Your method to check the Letter Code seams to base on old TYPO3 or tries to be backward compatible.

protected function prepareTwoLetterIsoCode(): string
    {
        DebuggerUtility::var_dump($GLOBALS['TSFE']->config['config']['language']);
        if (!empty($GLOBALS['TSFE']->config['config']['language'])) {
            $twoLetterIsoCode = $GLOBALS['TSFE']->config['config']['language'];
        } else {
            $twoLetterIsoCode = $this->getTwoLetterIsoCodeFromSiteConfig();
        }
        return $twoLetterIsoCode;
    }

Unfortunately in my context, TSFE is filled, but with a wrong value. So in TYPO3 12 the method must use $this->getTwoLetterIsoCodeFromSiteConfig(), even if TSFE is not empty.

I would suggest using the version number as the deciding factor. That could be like this (since typo3 9 the language is set in site config):

use TYPO3\CMS\Core\Information\Typo3Version;

protected function prepareTwoLetterIsoCode(): string
    {
        $typo3Version = GeneralUtility::makeInstance(Typo3Version::class);
        $versionString = $typo3Version->getVersion();
        $version = explode('.', $versionString);

        if ($version[0] < 9) {
            $twoLetterIsoCode = $GLOBALS['TSFE']->config['config']['language'];
        } else {
            $twoLetterIsoCode = $this->getTwoLetterIsoCodeFromSiteConfig();
        }
        return $twoLetterIsoCode;
    }

hope I could help. bye Martin

Gregor-Agnes commented 1 week ago

Thx and fixed in 341e366ba46f2ff7d7eaa72d62e10b05149f09aa