From 3a1867410a760c183e58115d9af687e262dac336 Mon Sep 17 00:00:00 2001 From: Nikita Hovratov <nikita.h@live.de> Date: Tue, 31 Aug 2021 14:25:29 +0200 Subject: [PATCH] [BUGFIX] Keep original request language for shortcuts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In #89871 (65dc060) a fix was introduced, that forces the link generation to use the requested language of shortcuts instead of the current language of the frontend. In addition, another call to getPageOverlay was added. This is in fact not necessary, as overlaying is already done implicitly in getPageShortcut. This introduced a falsy behaviour, where shortcuts without the current language available would create a URL with the entry point of the fallback language. This can be fixed by simply using the request language from the original $menuItem variable before processing. Resolves: #94677 Related: #89871 Releases: master, 10.4 Change-Id: I5c9bd0439d821d5516a5cb58cdf53df6b63c3aab Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/70836 Tested-by: core-ci <typo3@b13.com> Tested-by: Stefan Bürk <stefan@buerk.tech> Tested-by: Benni Mack <benni@typo3.org> Reviewed-by: Stefan Bürk <stefan@buerk.tech> Reviewed-by: Benni Mack <benni@typo3.org> --- .../Menu/AbstractMenuContentObject.php | 5 +- .../Fixtures/ScenarioG.yaml | 52 ++++++++++++ .../LocalizedPageRendering/ScenarioGTest.php | 84 +++++++++++++++++++ 3 files changed, 137 insertions(+), 4 deletions(-) create mode 100644 typo3/sysext/frontend/Tests/Functional/SiteHandling/LocalizedPageRendering/Fixtures/ScenarioG.yaml create mode 100644 typo3/sysext/frontend/Tests/Functional/SiteHandling/LocalizedPageRendering/ScenarioGTest.php diff --git a/typo3/sysext/frontend/Classes/ContentObject/Menu/AbstractMenuContentObject.php b/typo3/sysext/frontend/Classes/ContentObject/Menu/AbstractMenuContentObject.php index 561d89e0036d..4e1f4db6eb11 100644 --- a/typo3/sysext/frontend/Classes/ContentObject/Menu/AbstractMenuContentObject.php +++ b/typo3/sysext/frontend/Classes/ContentObject/Menu/AbstractMenuContentObject.php @@ -1299,9 +1299,6 @@ abstract class AbstractMenuContentObject [], true ); - if (isset($menuItem['_PAGES_OVERLAY_LANGUAGE'])) { - $shortcut = $tsfe->sys_page->getPageOverlay($shortcut, $menuItem['_PAGES_OVERLAY_LANGUAGE']); - } } catch (\Exception $ex) { } if (!is_array($shortcut)) { @@ -1311,7 +1308,7 @@ abstract class AbstractMenuContentObject // Only setting url, not target $LD['totalURL'] = $this->parent_cObj->typoLink_URL([ 'parameter' => $shortcut['uid'], - 'language' => $shortcut['_PAGES_OVERLAY_REQUESTEDLANGUAGE'] ?? 'current', + 'language' => $menuItem['_PAGES_OVERLAY_REQUESTEDLANGUAGE'] ?? 'current', 'additionalParams' => $addParams . $this->I['val']['additionalParams'] . ($menuItem['_ADD_GETVARS'] ?? ''), 'linkAccessRestrictedPages' => !empty($this->mconf['showAccessRestrictedPages']), ]); diff --git a/typo3/sysext/frontend/Tests/Functional/SiteHandling/LocalizedPageRendering/Fixtures/ScenarioG.yaml b/typo3/sysext/frontend/Tests/Functional/SiteHandling/LocalizedPageRendering/Fixtures/ScenarioG.yaml new file mode 100644 index 000000000000..fe414c98062e --- /dev/null +++ b/typo3/sysext/frontend/Tests/Functional/SiteHandling/LocalizedPageRendering/Fixtures/ScenarioG.yaml @@ -0,0 +1,52 @@ +__variables: + - &pageStandard 0 + - &pageShortcut 4 + - &contentText 'text' + - &idAcmeRootPage 1000 + +entitySettings: + '*': + nodeColumnName: 'pid' + columnNames: {id: 'uid', language: 'sys_language_uid'} + defaultValues: {pid: 0} + page: + isNode: true + tableName: 'pages' + parentColumnName: 'pid' + languageColumnNames: ['l10n_parent', 'l10n_source'] + columnNames: {type: 'doktype', root: 'is_siteroot', mount: 'mount_pid', visitorGroups: 'fe_group'} + defaultValues: {hidden: 0, doktype: *pageStandard} + valueInstructions: + shortcut: + first: {shortcut: 0, shortcut_mode: 1} + content: + tableName: 'tt_content' + languageColumnNames: ['l18n_parent', 'l10n_source'] + columnNames: {title: 'header', type: 'CType', column: 'colPos'} + defaultValues: {hidden: 0, type: *contentText, column: 0} + language: + tableName: 'sys_language' + columnNames: {code: 'language_isocode'} + typoscript: + tableName: 'sys_template' + valueInstructions: + type: + site: {root: 1, clear: 1} + +entities: + language: + - self: {id: 1, title: 'German', code: 'de'} + - self: {id: 2, title: 'Swiss German', code: 'de'} + page: + - self: {id: *idAcmeRootPage, title: 'EN: Root', root: true, slug: '/'} + children: + - self: {id: 1100, title: 'EN: Welcome', slug: '/hello'} + languageVariants: + - self: { id: 1101, title: 'DE: Willkommen', language: 1, slug: '/willkommen' } + - self: { id: 1102, title: 'DE-CH: Willkommen', language: 2, slug: '/willkommen' } + - self: {id: 1200, title: 'EN: About us', slug: '/about-us'} + languageVariants: + - self: {id: 1201, title: 'DE: Über uns', language: 1, slug: '/ueber-uns'} + - self: {id: 1300, title: 'EN: Shortcut to about', slug: '/shortcut-to-about', type: *pageShortcut, shortcut: 1200, l18n_cfg: 0, l10n_state: '{"shortcut":"custom"}'} + languageVariants: + - self: {id: 1301, title: 'DE: Abkürzung zu Über uns', language: 1, slug: '/shortcut-to-about', type: *pageShortcut, shortcut: 1200, l18n_cfg: 0, l10n_state: '{"shortcut":"custom"}'} diff --git a/typo3/sysext/frontend/Tests/Functional/SiteHandling/LocalizedPageRendering/ScenarioGTest.php b/typo3/sysext/frontend/Tests/Functional/SiteHandling/LocalizedPageRendering/ScenarioGTest.php new file mode 100644 index 000000000000..7b686d9a81bc --- /dev/null +++ b/typo3/sysext/frontend/Tests/Functional/SiteHandling/LocalizedPageRendering/ScenarioGTest.php @@ -0,0 +1,84 @@ +<?php + +declare(strict_types=1); + +/* + * This file is part of the TYPO3 CMS project. + * + * It is free software; you can redistribute it and/or modify it under + * the terms of the GNU General Public License, either version 2 + * of the License, or any later version. + * + * For the full copyright and license information, please read the + * LICENSE.txt file that was distributed with this source code. + * + * The TYPO3 project - inspiring people to share! + */ + +namespace TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\LocalizedPageRendering; + +/** + * Scenario prerequisites: + * Site configuration has localizations + * default language: EN + * first language: DE + * no fallbacks configured + * second language: DE-CH + * fallback to DE, EN + * + * Home page is localized into DE + * + * This scenario covers the issue for https://forge.typo3.org/issues/94677 + * + * Generated menu shortcut links, which point to an untranslated page, but + * have a fallback in place, should keep the current language and not switch + * to the translation language. + */ +class ScenarioGTest extends AbstractLocalizedPagesTestCase +{ + protected function setUp(): void + { + parent::setUp(); + + $this->writeSiteConfiguration( + 'acme-com', + $this->buildSiteConfiguration(1000, 'https://acme.com/'), + [ + $this->buildDefaultLanguageConfiguration('EN', 'https://acme.com/en'), + $this->buildLanguageConfiguration('DE', 'https://acme.com/de'), + $this->buildLanguageConfiguration('DE-CH', 'https://acme.com/de-ch', ['DE', 'EN']), + ] + ); + + $this->setUpDatabaseWithYamlPayload(__DIR__ . '/Fixtures/ScenarioG.yaml'); + } + + /** + * @return array + */ + public function menuDataProvider(): array + { + return [ + [ + 'url' => 'https://acme.com/de-ch/willkommen', + 'menu' => [ + ['title' => 'DE-CH: Willkommen', 'link' => '/de-ch/willkommen'], + ['title' => 'DE: Über uns', 'link' => '/de-ch/ueber-uns'], + ['title' => 'DE: Abkürzung zu Über uns', 'link' => '/de-ch/ueber-uns'], + ], + ], + ]; + } + + /** + * @param string $url + * @param array $expectedMenu + * + * @test + * @dataProvider menuDataProvider + */ + public function pageMenuIsRendered(string $url, array $expectedMenu): void + { + $this->assertMenu($url, $expectedMenu); + } +} -- GitLab