Skip to content

Commit

Permalink
[BUGFIX] Have stdWrap.lang use Site concept
Browse files Browse the repository at this point in the history
When building TypoScript like this:

10 = TEXT
10.value = English
10.lang.dk = danish

This does not work currently as it relies on "config.language". This part
has been forgotten while the Site Handling was initially implemented into
the TYPO3 core.

The patch adapts the changes to make use of Site Handling if it is available,
but falls back to the TypoScript options (for PseudoSites).

Resolves: #87712
Releases: master, 9.5
Change-Id: I5e2b97b178e6ccafec1ff7556d41321ea67fb45a
Reviewed-on: https://review.typo3.org/59704
Tested-by: TYPO3com <noreply@typo3.com>
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
  • Loading branch information
bmack committed Feb 15, 2019
1 parent 2c2a238 commit 91898b9
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 10 deletions.
Expand Up @@ -1752,14 +1752,16 @@ public function stdWrap_setCurrent($content = '', $conf = [])
*/
public function stdWrap_lang($content = '', $conf = [])
{
$tsfe = $this->getTypoScriptFrontendController();
if (
isset($conf['lang.'])
&& isset($tsfe->config['config']['language'])
&& $tsfe->config['config']['language']
&& isset($conf['lang.'][$tsfe->config['config']['language']])
) {
$content = $conf['lang.'][$tsfe->config['config']['language']];
$request = $GLOBALS['TYPO3_REQUEST'] ?? null;
$siteLanguage = $request ? $request->getAttribute('language') : null;
if ($siteLanguage instanceof SiteLanguage) {
$currentLanguageCode = $siteLanguage->getTypo3Language();
} else {
$tsfe = $this->getTypoScriptFrontendController();
$currentLanguageCode = $tsfe->config['config']['language'] ?? null;
}
if ($currentLanguageCode && isset($conf['lang.'][$currentLanguageCode])) {
$content = $conf['lang.'][$currentLanguageCode];
}
return $content;
}
Expand Down
Expand Up @@ -25,6 +25,7 @@
use TYPO3\CMS\Core\Context\UserAspect;
use TYPO3\CMS\Core\Context\WorkspaceAspect;
use TYPO3\CMS\Core\Core\ApplicationContext;
use TYPO3\CMS\Core\Http\ServerRequest;
use TYPO3\CMS\Core\Http\Uri;
use TYPO3\CMS\Core\LinkHandling\LinkService;
use TYPO3\CMS\Core\Log\Logger;
Expand Down Expand Up @@ -6301,7 +6302,7 @@ public function stdWrap_langDataProvider(): array
}

/**
* Check if stdWrap_lang works properly.
* Check if stdWrap_lang works properly with TypoScript.
*
* @param string $expected The expected value.
* @param string $input The input value.
Expand All @@ -6310,7 +6311,7 @@ public function stdWrap_langDataProvider(): array
* @test
* @dataProvider stdWrap_langDataProvider
*/
public function stdWrap_lang(string $expected, string $input, array $conf, string $language): void
public function stdWrap_langViaTSFE(string $expected, string $input, array $conf, string $language): void
{
if ($language) {
$this->frontendControllerMock
Expand All @@ -6322,6 +6323,31 @@ public function stdWrap_lang(string $expected, string $input, array $conf, strin
);
}

/**
* Check if stdWrap_lang works properly with site handling.
*
* @param string $expected The expected value.
* @param string $input The input value.
* @param array $conf Properties: lang.xy.
* @param string $language For $TSFE->config[config][language].
* @test
* @dataProvider stdWrap_langDataProvider
*/
public function stdWrap_langViaSiteLanguage(string $expected, string $input, array $conf, string $language): void
{
if ($language) {
$request = new ServerRequest();
$GLOBALS['TYPO3_REQUEST'] = $request->withAttribute(
'language',
new SiteLanguage(2, 'en_UK', new Uri(), ['typo3Language' => $language])
);
}
$this->assertSame(
$expected,
$this->subject->stdWrap_lang($input, $conf)
);
}

/**
* Check if stdWrap_listNum works properly.
*
Expand Down

0 comments on commit 91898b9

Please sign in to comment.