[BUGFIX] Do not force content_fallback to default page language 26/54426/7
authorBenni Mack <benni@typo3.org>
Tue, 17 Oct 2017 22:06:21 +0000 (00:06 +0200)
committerSusanne Moog <susanne.moog@typo3.org>
Mon, 23 Oct 2017 07:40:27 +0000 (09:40 +0200)
If a page translation is not available, the TypoScript option
`config.sys_language_mode` has the option
`content_fallback;listofuids` to define to which other language
translations should be fallen back.

However, if NONE of the defined page translations are available,
a fallback to the DEFAULT language is made (because the
foreach just does not apply) which can not be stopped at all.

To define an explicit 404 when a translated page NOR its
fallbacks are available the special keyword "pageNotFound" is added,
which can be added to
`config.sys_language_mode = content_fallback;3,2,pageNotFound`
and if none of 3,2 are available, a page not found message
is thrown.

Resolves: #82794
Releases: master, 8.7
Change-Id: I90af4e9f9685ffc7db8c562207e3df08786c0ca9
Reviewed-on: https://review.typo3.org/54426
Tested-by: TYPO3com <no-reply@typo3.com>
Tested-by: Sascha Rademacher <sascha.rademacher+typo3@gmail.com>
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
Reviewed-by: Susanne Moog <susanne.moog@typo3.org>
Tested-by: Susanne Moog <susanne.moog@typo3.org>
typo3/sysext/core/Documentation/Changelog/master/Important-82794-AddedSysLanguageModeFallbackStop.rst [new file with mode: 0644]
typo3/sysext/frontend/Classes/Controller/TypoScriptFrontendController.php

diff --git a/typo3/sysext/core/Documentation/Changelog/master/Important-82794-AddedSysLanguageModeFallbackStop.rst b/typo3/sysext/core/Documentation/Changelog/master/Important-82794-AddedSysLanguageModeFallbackStop.rst
new file mode 100644 (file)
index 0000000..76ba8cc
--- /dev/null
@@ -0,0 +1,31 @@
+.. include:: ../../Includes.txt
+
+======================================================================
+Important: #82794 - Added config.sys_language_mode = fallback;3,2,stop
+======================================================================
+
+See :issue:`82794`
+
+Description
+===========
+
+If a translation (language UID 5) has a TypoScript configuration to
+`config.sys_language_mode = content_fallback;3,2` the definition is that if this page is not
+available in this translation (language=5) then check if a translation for 3 and after that "2" is
+set.
+
+However, if none of the page translations is available, the fallback to "0" always applies.
+
+On a set up like:
+- language=0 is german
+- language=2 is english-worldwide
+- language=3 is english-US
+- language=5 is russian
+
+You would not want to fall back to german AT ALL.
+
+It is now possible to define a special keyword called "pageNotFound" to not fall back to
+sys_language_uid=0 if any other fallbacks do not work - so a 404 error page is thrown.
+`config.sys_language_mode = content_fallback;3,2,pageNotFound`
+
+.. index:: TypoScript
\ No newline at end of file
index e83df3d..edba1ff 100644 (file)
@@ -2574,13 +2574,24 @@ class TypoScriptFrontendController implements LoggerAwareInterface
                                 $this->pageNotFoundAndExit('Page is not available in the requested language (strict).');
                                 break;
                             case 'content_fallback':
-                                $fallBackOrder = GeneralUtility::intExplode(',', $sys_language_content);
+                                // Setting content uid (but leaving the sys_language_uid) when a content_fallback
+                                // value was found.
+                                $fallBackOrder = GeneralUtility::trimExplode(',', $sys_language_content);
                                 foreach ($fallBackOrder as $orderValue) {
-                                    if ((string)$orderValue === '0' || !empty($this->sys_page->getPageOverlay($this->id, $orderValue))) {
-                                        $this->sys_language_content = $orderValue;
-                                        // Setting content uid (but leaving the sys_language_uid)
+                                    if ($orderValue === '0' || $orderValue === '') {
+                                        $this->sys_language_content = 0;
                                         break;
                                     }
+                                    if (MathUtility::canBeInterpretedAsInteger($orderValue) && !empty($this->sys_page->getPageOverlay($this->id, (int)$orderValue))) {
+                                        $this->sys_language_content = (int)$orderValue;
+                                        break;
+                                    }
+                                    if ($orderValue === 'pageNotFound') {
+                                        // The existing fallbacks have not been found, but instead of continuing
+                                        // page rendering with default language, a "page not found" message should be shown
+                                        // instead.
+                                        $this->pageNotFoundAndExit('Page is not available in the requested language (fallbacks did not apply).');
+                                    }
                                 }
                                 break;
                             case 'ignore':