From 65dc0603115ee7a70148c2d6fb095102e8f51a39 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Christian=20E=C3=9Fl?= <indy.essl@gmail.com>
Date: Fri, 6 Dec 2019 10:24:23 +0100
Subject: [PATCH] [BUGFIX] Fix wrong language parameters in language menu
 shortcut links

When a shortcut page is used for a translated page, but its parent
is not of type shortcut, the generated link would always use the
current language of the frontend context instead of the actual
required language set in _PAGES_OVERLAY_REQUESTEDLANGUAGE.

Resolves: #89871
Related: #81657
Related: #86595
Related: #19114
Releases: master, 10.4
Change-Id: Iaa4e682e2bd79852b5e586b1764fd42ae8676644
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/62552
Tested-by: Richard Haeser <richard@richardhaeser.com>
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Benni Mack <benni@typo3.org>
Reviewed-by: Richard Haeser <richard@richardhaeser.com>
Reviewed-by: Benni Mack <benni@typo3.org>
---
 .../ContentObject/Menu/AbstractMenuContentObject.php       | 5 ++++-
 .../LocalizedPageRendering/Fixtures/ScenarioD.yaml         | 5 ++++-
 .../SiteHandling/LocalizedPageRendering/ScenarioDTest.php  | 7 +++++++
 3 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/typo3/sysext/frontend/Classes/ContentObject/Menu/AbstractMenuContentObject.php b/typo3/sysext/frontend/Classes/ContentObject/Menu/AbstractMenuContentObject.php
index 1d901c8e54a8..210958dbe568 100644
--- a/typo3/sysext/frontend/Classes/ContentObject/Menu/AbstractMenuContentObject.php
+++ b/typo3/sysext/frontend/Classes/ContentObject/Menu/AbstractMenuContentObject.php
@@ -1355,6 +1355,9 @@ 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)) {
@@ -1364,7 +1367,7 @@ abstract class AbstractMenuContentObject
             // Only setting url, not target
             $LD['totalURL'] = $this->parent_cObj->typoLink_URL([
                 'parameter' => $shortcut['uid'],
-                'language' => 'current',
+                'language' => $shortcut['_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/ScenarioD.yaml b/typo3/sysext/frontend/Tests/Functional/SiteHandling/LocalizedPageRendering/Fixtures/ScenarioD.yaml
index fd5fc61222bb..844262ed94f4 100644
--- a/typo3/sysext/frontend/Tests/Functional/SiteHandling/LocalizedPageRendering/Fixtures/ScenarioD.yaml
+++ b/typo3/sysext/frontend/Tests/Functional/SiteHandling/LocalizedPageRendering/Fixtures/ScenarioD.yaml
@@ -48,4 +48,7 @@ entities:
         - self: {id: 1300, title: 'EN: Products', slug: '/products'}
           languageVariants:
             - self: {id: 1302, title: 'DE-CH: Produkte', language: 2, slug: '/produkte'}
-        - self: {id: 1400, title: 'EN: Shortcut to welcome', slug: '/shortcut-to-welcome', type: *pageShortcut, shortcut: 1100, l18n_cfg: 0}
+        - self: {id: 1400, title: 'EN: Shortcut to welcome', slug: '/shortcut-to-welcome', type: *pageShortcut, shortcut: 1100, l18n_cfg: 0, l10n_state: '{"shortcut":"custom"}'}
+        - self: {id: 1500, title: 'EN: Company', slug: '/company'}
+          languageVariants:
+            - self: {id: 1501, title: 'DE: Unternehmen', language: 1, slug: '/shortcut-to-about', type: *pageShortcut, shortcut: 1200, shortcut_mode: 0, l18n_cfg: 0, l10n_state: '{"shortcut":"custom","shortcut_mode":"custom"}'}
diff --git a/typo3/sysext/frontend/Tests/Functional/SiteHandling/LocalizedPageRendering/ScenarioDTest.php b/typo3/sysext/frontend/Tests/Functional/SiteHandling/LocalizedPageRendering/ScenarioDTest.php
index d7439c8e6e9a..0455840c5571 100644
--- a/typo3/sysext/frontend/Tests/Functional/SiteHandling/LocalizedPageRendering/ScenarioDTest.php
+++ b/typo3/sysext/frontend/Tests/Functional/SiteHandling/LocalizedPageRendering/ScenarioDTest.php
@@ -29,6 +29,7 @@ namespace TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\LocalizedPageRenderin
  *   Home page is not localized into any language and has l18n_cfg=2 set
  *   "About" page is localized into DE and has l18n_cfg=2 set
  *   "Products" page is localized into DE-CH and has l18n_cfg=2 set
+ *   "Company" page is of type "default" in EN and of type "shortcut" in DE, redirecting to page "About"
  *
  * Scenario expectations:
  *   Calling home page in EN renders page in EN
@@ -38,6 +39,9 @@ namespace TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\LocalizedPageRenderin
  *   Calling "about" page in EN renders page in EN
  *   Calling "about" page in DE renders page in DE
  *   Calling "about" page in DE-CH renders page in DE-CH
+ *
+ *   Calling "company" page in EN renders page in EN
+ *   Calling "company" page in DE redirects to page "About" in DE
  */
 class ScenarioDTest extends AbstractLocalizedPagesTestCase
 {
@@ -145,6 +149,7 @@ class ScenarioDTest extends AbstractLocalizedPagesTestCase
                     ['title' => 'EN: About us', 'link' => '/en/about-us'],
                     ['title' => 'EN: Products', 'link' => '/en/products'],
                     ['title' => 'EN: Shortcut to welcome', 'link' => '/en/hello'],
+                    ['title' => 'EN: Company', 'link' => '/en/company'],
                 ],
             ],
             [
@@ -154,12 +159,14 @@ class ScenarioDTest extends AbstractLocalizedPagesTestCase
                     ['title' => 'EN: About us', 'link' => '/en/about-us'],
                     ['title' => 'EN: Products', 'link' => '/en/products'],
                     ['title' => 'EN: Shortcut to welcome', 'link' => '/en/hello'],
+                    ['title' => 'EN: Company', 'link' => '/en/company'],
                 ],
             ],
             [
                 'url' => 'https://acme.com/de/ueber-uns',
                 'menu' => [
                     ['title' => 'DE: Ãœber uns', 'link' => '/de/ueber-uns'],
+                    ['title' => 'DE: Unternehmen', 'link' => '/de/ueber-uns'],
                 ],
             ],
             [
-- 
GitLab