Commit dff9676f authored by Benni Mack's avatar Benni Mack
Browse files

[TASK] Simplify TSFE->settingLanguage

$TSFE->settingLanguage() resolve possibly language
overlays when a page is accessed. This method
has been around for a long time, and with the introduction
of Site handling and its language handling, this method
can be simplified.

* sys_page->getPageOverlay() now is handed in the full default
  language record which is tried to be overlaid, but also
  resolves the full fallback chain.
  This way, including all the caching information from sys_page
  is used, TSFE does not need to retrieve the full record
  from sys_page->getPageOverlay() manually anymore.
* FallbackChain "ignore" can be removed, as it is not possible
  anymore since at least TYPO3 v10 to ignore the fallback
  logic, and the condition can be removed.

Resolves: #99711
Releases: main
Change-Id: I056e12f1a2d0805eb9c9cfb211a37fb83974c661
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/77422


Tested-by: core-ci's avatarcore-ci <typo3@b13.com>
Tested-by: Oliver Bartsch's avatarOliver Bartsch <bo@cedev.de>
Tested-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
Tested-by: Georg Ringer's avatarGeorg Ringer <georg.ringer@gmail.com>
Reviewed-by: Oliver Bartsch's avatarOliver Bartsch <bo@cedev.de>
Reviewed-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
Reviewed-by: Georg Ringer's avatarGeorg Ringer <georg.ringer@gmail.com>
parent 83600741
......@@ -41,7 +41,7 @@ use TYPO3\CMS\Core\Context\Exception\AspectPropertyNotFoundException;
* - previously known as $TSFE->sys_language_mode
* - defines "contentId" based on "if the current page is available in this language"
* - "strict"
* - "fallback" if current page is not available, check the fallbackChain"
* - "fallback" if current page is not available, check the "fallbackChain"
* - "fallbackAndIgnore"
*
* "overlayType"
......@@ -143,9 +143,6 @@ class LanguageAspect implements AspectInterface
if (empty($this->fallbackChain)) {
return 'strict';
}
if ($this->fallbackChain === [-1]) {
return 'ignore';
}
return 'content_fallback';
}
......
......@@ -262,7 +262,7 @@ class ActionTest extends AbstractActionTestCase
parent::copyContentToLanguageOfRelation();
$this->assertCSVDataSet(__DIR__ . '/DataSet/copyContentToLanguageOfRelation.csv');
// Set up "dk" to not have overlays
// Set up "da" to not have overlays
$languageConfiguration = $this->siteLanguageConfiguration;
$languageConfiguration[self::VALUE_LanguageId]['fallbackType'] = 'free';
$this->setUpFrontendSite(1, $languageConfiguration);
......
......@@ -124,7 +124,7 @@ class ActionTest extends AbstractActionTestCase
parent::copyParentContentToLanguageWithAllChildren();
$this->assertCSVDataSet(__DIR__ . '/DataSet/copyParentContentToLanguageWithAllChildren.csv');
// Set up "dk" to not have overlays
// Set up "da" to not have overlays
$languageConfiguration = $this->siteLanguageConfiguration;
$languageConfiguration[self::VALUE_LanguageId]['fallbackType'] = 'free';
$this->setUpFrontendSite(1, $languageConfiguration);
......
......@@ -126,7 +126,7 @@ class ActionTest extends AbstractActionTestCase
parent::copyParentContentToLanguageWithAllChildren();
$this->assertCSVDataSet(__DIR__ . '/DataSet/copyParentContentToLanguageWAllChildren.csv');
// Set up "dk" to not have overlays
// Set up "da" to not have overlays
$languageConfiguration = $this->siteLanguageConfiguration;
$languageConfiguration[self::VALUE_LanguageId]['fallbackType'] = 'free';
$this->setUpFrontendSite(1, $languageConfiguration);
......
......@@ -166,7 +166,7 @@ class ActionTest extends AbstractActionTestCase
parent::copyContentToLanguage();
$this->assertCSVDataSet(__DIR__ . '/DataSet/copyContentToLanguage.csv');
// Set up "dk" to not have overlays
// Set up "da" to not have overlays
$languageConfiguration = $this->siteLanguageConfiguration;
$languageConfiguration[self::VALUE_LanguageId]['fallbackType'] = 'free';
$this->setUpFrontendSite(1, $languageConfiguration);
......@@ -187,7 +187,7 @@ class ActionTest extends AbstractActionTestCase
parent::copyContentToLanguageWithLanguageSynchronization();
$this->assertCSVDataSet(__DIR__ . '/DataSet/copyContentToLanguageWSynchronization.csv');
// Set up "dk" to not have overlays
// Set up "da" to not have overlays
$languageConfiguration = $this->siteLanguageConfiguration;
$languageConfiguration[self::VALUE_LanguageId]['fallbackType'] = 'free';
$this->setUpFrontendSite(1, $languageConfiguration);
......@@ -208,7 +208,7 @@ class ActionTest extends AbstractActionTestCase
parent::copyContentToLanguageWithLocalizationExclude();
$this->assertCSVDataSet(__DIR__ . '/DataSet/copyContentToLanguageWExclude.csv');
// Set up "dk" to not have overlays
// Set up "da" to not have overlays
$languageConfiguration = $this->siteLanguageConfiguration;
$languageConfiguration[self::VALUE_LanguageId]['fallbackType'] = 'free';
$this->setUpFrontendSite(1, $languageConfiguration);
......
......@@ -212,7 +212,7 @@ class ActionTest extends AbstractActionWorkspacesTestCase
parent::copyContentToLanguage();
$this->assertCSVDataSet(__DIR__ . '/DataSet/copyContentToLanguage.csv');
// Set up "dk" to not have overlays
// Set up "da" to not have overlays
$languageConfiguration = $this->siteLanguageConfiguration;
$languageConfiguration[self::VALUE_LanguageId]['fallbackType'] = 'free';
$this->setUpFrontendSite(1, $languageConfiguration);
......
......@@ -197,7 +197,7 @@ class ActionTest extends AbstractActionWorkspacesTestCase
$this->actionService->publishRecord(self::TABLE_Content, $this->recordIds['localizedContentId']);
$this->assertCSVDataSet(__DIR__ . '/DataSet/copyContentToLanguage.csv');
// Set up "dk" to not have overlays
// Set up "da" to not have overlays
$languageConfiguration = $this->siteLanguageConfiguration;
$languageConfiguration[self::VALUE_LanguageId]['fallbackType'] = 'free';
$this->setUpFrontendSite(1, $languageConfiguration);
......@@ -219,7 +219,7 @@ class ActionTest extends AbstractActionWorkspacesTestCase
$this->actionService->publishRecord(self::TABLE_Content, $this->recordIds['localizedContentId']);
$this->assertCSVDataSet(__DIR__ . '/DataSet/copyContentToLanguageFromNonDefaultLanguage.csv');
// Set up "dk" to not have overlays
// Set up "da" to not have overlays
$languageConfiguration = $this->siteLanguageConfiguration;
$languageConfiguration[self::VALUE_LanguageIdSecond]['fallbackType'] = 'free';
$this->setUpFrontendSite(1, $languageConfiguration);
......
......@@ -188,7 +188,7 @@ class ActionTest extends AbstractActionWorkspacesTestCase
$this->actionService->publishWorkspace(self::VALUE_WorkspaceId);
$this->assertCSVDataSet(__DIR__ . '/DataSet/copyContentToLanguage.csv');
// Set up "dk" to not have overlays
// Set up "da" to not have overlays
$languageConfiguration = $this->siteLanguageConfiguration;
$languageConfiguration[self::VALUE_LanguageId]['fallbackType'] = 'free';
$this->setUpFrontendSite(1, $languageConfiguration);
......
......@@ -1637,12 +1637,13 @@ class TypoScriptFrontendController implements LoggerAwareInterface
$languageContentId = $languageAspect->getContentId();
$pageTranslationVisibility = new PageTranslationVisibility((int)($this->page['l18n_cfg'] ?? 0));
// If sys_language_uid is set to another language than default:
// If the incoming language is set to another language than default
if ($languageAspect->getId() > 0) {
// Request the overlay record for the sys_language_uid:
$olRec = $this->sys_page->getPageOverlay($this->id, $languageAspect->getId());
if (empty($olRec)) {
// If requested translation is not available:
// Request the translation for the requested language
$olRec = $this->sys_page->getPageOverlay($this->page, $languageAspect);
$overlaidLanguageId = (int)($olRec['sys_language_uid'] ?? 0);
if ($overlaidLanguageId !== $languageAspect->getId()) {
// If requested translation is not available
if ($pageTranslationVisibility->shouldHideTranslationIfNoTranslatedRecordExists()) {
$response = GeneralUtility::makeInstance(ErrorController::class)->pageNotFoundAction(
$request,
......@@ -1651,7 +1652,7 @@ class TypoScriptFrontendController implements LoggerAwareInterface
);
throw new PropagateResponseException($response, 1533931388);
}
switch ((string)$languageAspect->getLegacyLanguageMode()) {
switch ($languageAspect->getLegacyLanguageMode()) {
case 'strict':
$response = GeneralUtility::makeInstance(ErrorController::class)->pageNotFoundAction(
$request,
......@@ -1659,7 +1660,6 @@ class TypoScriptFrontendController implements LoggerAwareInterface
['code' => PageAccessFailureReasons::LANGUAGE_NOT_AVAILABLE_STRICT_MODE]
);
throw new PropagateResponseException($response, 1533931395);
case 'fallback':
case 'content_fallback':
// Setting content uid (but leaving the sys_language_uid) when a content_fallback
// value was found.
......@@ -1668,7 +1668,7 @@ class TypoScriptFrontendController implements LoggerAwareInterface
$languageContentId = 0;
break;
}
if (MathUtility::canBeInterpretedAsInteger($orderValue) && !empty($this->sys_page->getPageOverlay($this->id, (int)$orderValue))) {
if (MathUtility::canBeInterpretedAsInteger($orderValue) && $overlaidLanguageId === (int)$orderValue) {
$languageContentId = (int)$orderValue;
break;
}
......@@ -1685,9 +1685,6 @@ class TypoScriptFrontendController implements LoggerAwareInterface
}
}
break;
case 'ignore':
$languageContentId = $languageAspect->getId();
break;
default:
// Default is that everything defaults to the default language...
$languageId = ($languageContentId = 0);
......@@ -1703,10 +1700,9 @@ class TypoScriptFrontendController implements LoggerAwareInterface
$languageAspect->getFallbackChain()
);
// Setting the site language if an overlay record was found (which it is only if a language is used)
// We'll do this every time since the language aspect might have changed now
// Setting the $this->page if an overlay record was found (which it is only if a language is used)
// Doing this ensures that page properties like the page title are resolved in the correct language
$this->page = $this->sys_page->getPageOverlay($this->page, $languageAspect->getContentId());
$this->page = $olRec;
}
// Set the language aspect
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment