diff --git a/typo3/sysext/extbase/Classes/Persistence/Generic/Storage/Typo3DbBackend.php b/typo3/sysext/extbase/Classes/Persistence/Generic/Storage/Typo3DbBackend.php index c3792f5..b8f46a2 100644 --- a/typo3/sysext/extbase/Classes/Persistence/Generic/Storage/Typo3DbBackend.php +++ b/typo3/sysext/extbase/Classes/Persistence/Generic/Storage/Typo3DbBackend.php @@ -823,7 +823,7 @@ class Typo3DbBackend implements BackendInterface, \TYPO3\CMS\Core\SingletonInter ) { if (in_array($row[$GLOBALS['TCA'][$tableName]['ctrl']['languageField']], array(-1, 0))) { $overlayMode = $querySettings->getLanguageMode() === 'strict' ? 'hideNonTranslated' : ''; - $row = $pageRepository->getRecordOverlay($tableName, $row, $querySettings->getLanguageUid(), $overlayMode); + $row = $pageRepository->getRecordOverlayWithoutFallback($tableName, $row, $querySettings->getLanguageUid(), $overlayMode); } } if ($row !== NULL && is_array($row)) { diff --git a/typo3/sysext/frontend/Classes/ContentObject/ContentContentObject.php b/typo3/sysext/frontend/Classes/ContentObject/ContentContentObject.php index dddd02e..a11fdc8 100644 --- a/typo3/sysext/frontend/Classes/ContentObject/ContentContentObject.php +++ b/typo3/sysext/frontend/Classes/ContentObject/ContentContentObject.php @@ -83,7 +83,19 @@ class ContentContentObject extends \TYPO3\CMS\Frontend\ContentObject\AbstractCon if ($conf['table'] == 'pages') { $row = $GLOBALS['TSFE']->sys_page->getPageOverlay($row); } else { - $row = $GLOBALS['TSFE']->sys_page->getRecordOverlay($conf['table'], $row, $GLOBALS['TSFE']->sys_language_content, $GLOBALS['TSFE']->sys_language_contentOL); + $fallbackChain = NULL; + if (isset($conf['languageFallbackChain'])) { + $fallbackChain = \TYPO3\CMS\Core\Utility\GeneralUtility::intExplode(',', $conf['languageFallbackChain']); + } + $pageLanguageBinding = TRUE; + if (isset($conf['respectPageLanguageBinding']) && + $conf['respectPageLanguageBinding'] == '0' + ) { + $pageLanguageBinding = FALSE; + } + $row = $GLOBALS['TSFE']->sys_page->getRecordOverlayWithFallback( + $conf['table'], $row, $GLOBALS['TSFE']->sys_language_content, $GLOBALS['TSFE']->sys_language_contentOL, $fallbackChain, $pageLanguageBinding + ); } } // Might be unset in the sys_language_contentOL diff --git a/typo3/sysext/frontend/Classes/ContentObject/Menu/AbstractMenuContentObject.php b/typo3/sysext/frontend/Classes/ContentObject/Menu/AbstractMenuContentObject.php index 98b9dcf..182532d 100644 --- a/typo3/sysext/frontend/Classes/ContentObject/Menu/AbstractMenuContentObject.php +++ b/typo3/sysext/frontend/Classes/ContentObject/Menu/AbstractMenuContentObject.php @@ -990,7 +990,7 @@ class AbstractMenuContentObject { $tok = TRUE; // There is an alternative language active AND the current page requires a translation: if ($GLOBALS['TSFE']->sys_language_uid && GeneralUtility::hideIfNotTranslated($data['l18n_cfg'])) { - if (!$data['_PAGES_OVERLAY']) { + if (!$data['_PAGES_OVERLAY'] || ($data['_PAGES_OVERLAY_LANGUAGE'] != $data['sys_language_uid'])) { $tok = FALSE; } } @@ -1871,7 +1871,7 @@ class AbstractMenuContentObject { while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($resource)) { $this->sys_page->versionOL('tt_content', $row); if ($GLOBALS['TSFE']->sys_language_contentOL && $basePageRow['_PAGES_OVERLAY_LANGUAGE']) { - $row = $this->sys_page->getRecordOverlay('tt_content', $row, $basePageRow['_PAGES_OVERLAY_LANGUAGE'], $GLOBALS['TSFE']->sys_language_contentOL); + $row = $this->sys_page->getRecordOverlayWithFallback('tt_content', $row, $basePageRow['_PAGES_OVERLAY_LANGUAGE'], $GLOBALS['TSFE']->sys_language_contentOL); } if ($this->mconf['sectionIndex.']['type'] !== 'all') { $doIncludeInSectionIndex = $row['sectionIndex'] >= 1; diff --git a/typo3/sysext/frontend/Classes/ContentObject/RecordsContentObject.php b/typo3/sysext/frontend/Classes/ContentObject/RecordsContentObject.php index e130814..b809c56 100644 --- a/typo3/sysext/frontend/Classes/ContentObject/RecordsContentObject.php +++ b/typo3/sysext/frontend/Classes/ContentObject/RecordsContentObject.php @@ -97,7 +97,19 @@ class RecordsContentObject extends AbstractContentObject { if ($val['table'] === 'pages') { $row = $GLOBALS['TSFE']->sys_page->getPageOverlay($row); } else { - $row = $GLOBALS['TSFE']->sys_page->getRecordOverlay($val['table'], $row, $GLOBALS['TSFE']->sys_language_content, $GLOBALS['TSFE']->sys_language_contentOL); + $fallbackChain = NULL; + if (isset($conf['languageFallbackChain'])) { + $fallbackChain = \TYPO3\CMS\Core\Utility\GeneralUtility::intExplode(',', $conf['languageFallbackChain']); + } + $pageLanguageBinding = TRUE; + if (isset($conf['respectPageLanguageBinding']) && + $conf['respectPageLanguageBinding'] == '0' + ) { + $pageLanguageBinding = FALSE; + } + $row = $GLOBALS['TSFE']->sys_page->getRecordOverlayWithFallback( + $conf['table'], $row, $GLOBALS['TSFE']->sys_language_content, $GLOBALS['TSFE']->sys_language_contentOL, $fallbackChain, $pageLanguageBinding + ); } } } diff --git a/typo3/sysext/frontend/Classes/Controller/TypoScriptFrontendController.php b/typo3/sysext/frontend/Classes/Controller/TypoScriptFrontendController.php index 9116db7..8c24b86 100644 --- a/typo3/sysext/frontend/Classes/Controller/TypoScriptFrontendController.php +++ b/typo3/sysext/frontend/Classes/Controller/TypoScriptFrontendController.php @@ -656,6 +656,20 @@ class TypoScriptFrontendController { public $sys_language_content = 0; /** + * Contains the prioritized language fallback chain + * + * @var array + */ + public $languageFallbackChain = array(); + + /** + * Contains the prioritized language fallback chain for the current page + * + * @var array + */ + public $languageFallbackChainWithPageLanguageBinding = array(); + + /** * Site content overlay flag; If set - and sys_language_content is > 0 - , * records selected will try to look for a translation pointing to their uid. (If * configured in [ctrl][languageField] / [ctrl][transOrigP...] @@ -2710,7 +2724,9 @@ class TypoScriptFrontendController { // Get values from TypoScript: $this->sys_language_uid = ($this->sys_language_content = (int)$this->config['config']['sys_language_uid']); list($this->sys_language_mode, $sys_language_content) = GeneralUtility::trimExplode(';', $this->config['config']['sys_language_mode']); + $languageFallbackChain = GeneralUtility::intExplode(',', $this->config['config']['languageFallbackChain']); $this->sys_language_contentOL = $this->config['config']['sys_language_overlay']; + $this->sys_language_content_list = array($this->sys_language_uid); // If sys_language_uid is set to another language than default: if ($this->sys_language_uid > 0) { // check whether a shortcut is overwritten by a translated page @@ -2731,11 +2747,21 @@ class TypoScriptFrontendController { $this->pageNotFoundAndExit('Page is not available in the requested language (strict).'); break; case 'content_fallback': - $fallBackOrder = GeneralUtility::intExplode(',', $sys_language_content); - foreach ($fallBackOrder as $orderValue) { - if ((string)$orderValue === '0' || count($this->sys_page->getPageOverlay($this->id, $orderValue))) { - $this->sys_language_content = $orderValue; - // Setting content uid (but leaving the sys_language_uid) + // default is to fallback to default language + $this->sys_language_content = 0; + foreach ($languageFallbackChain as $languageId) { + // ignore default language + if ($this->sys_language_uid === $languageId || $languageId <= 0) { + continue; + } + $pageOverlay = $this->sys_page->getPageOverlay($this->id, $languageId); + if (count($pageOverlay)) { + // Setting content uid (but leaving the sys_language_uid) + $this->sys_language_content = $languageId; + // Remove all fields from page overlay which do not exist in $this->page + $pageOverlay = array_intersect_key($pageOverlay, $this->page); + // overlay page with existing page overlay + $this->page = array_merge($this->page, $pageOverlay); break; } } @@ -2750,8 +2776,25 @@ class TypoScriptFrontendController { } } } else { - // Setting sys_language if an overlay record was found (which it is only if a language is used) - $this->page = $this->sys_page->getPageOverlay($this->page, $this->sys_language_uid); + // Remove all fields from page overlay which do not exist in $this->page + $olRec = array_intersect_key($olRec, $this->page); + // overlay page with existing page overlay + $this->page = array_merge($this->page, $olRec); + } + // calculate the language fallback chains + if ($this->sys_language_mode === 'content_fallback') { + $this->languageFallbackChain = $languageFallbackChain; + foreach ($languageFallbackChain as $languageId) { + // ignore default language + if ($this->sys_language_uid === $languageId) { + continue; + } + $this->languageFallbackChain[] = $languageId; + if (count($this->sys_page->getPageOverlay($this->id, $languageId))) { + $this->languageFallbackChainWithPageLanguageBinding[] = $languageId; + } + } + } } // Setting sys_language_uid inside sys-page: diff --git a/typo3/sysext/frontend/Classes/Page/PageRepository.php b/typo3/sysext/frontend/Classes/Page/PageRepository.php index 249f7f1..a5b7d74 100644 --- a/typo3/sysext/frontend/Classes/Page/PageRepository.php +++ b/typo3/sysext/frontend/Classes/Page/PageRepository.php @@ -326,7 +326,9 @@ class PageRepository { */ public function getPageOverlay($pageInput, $lUid = -1) { // Initialize: + $noSpecialLanguageRequested = FALSE; if ($lUid < 0) { + $noSpecialLanguageRequested = TRUE; $lUid = $this->sys_language_uid; } $row = NULL; @@ -351,7 +353,18 @@ class PageRepository { // Was the id $page_id = $pageInput; } - if (count($fieldArr)) { + if (count($fieldArr)) { + $languageList = array(); + if ($noSpecialLanguageRequested) { + $languageList = array_unique(array_merge( + array($lUid), + $GLOBALS['TSFE']->languageFallbackChain, + array($GLOBALS['TSFE']->sys_language_content) + )); + $languageIds = implode(',', array_map('intval', $languageList)); + $languageClause = 'sys_language_uid IN (' . $languageIds . ') '; + } + // NOTE to enabledFields('pages_language_overlay'): // Currently the showHiddenRecords of TSFE set will allow // pages_language_overlay records to be selected as they are @@ -359,9 +372,35 @@ class PageRepository { // However you may argue that the showHiddenField flag should // determine this. But that's not how it's done right now. // Selecting overlay record: - $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(implode(',', $fieldArr), 'pages_language_overlay', 'pid=' . (int)$page_id . ' - AND sys_language_uid=' . (int)$lUid . $this->enableFields('pages_language_overlay'), '', '', '1'); - $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res); + if (!in_array('sys_language_uid', $fieldArr)) { + $fieldArr[] = 'sys_language_uid'; + } + $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery( + implode(',', $fieldArr), + 'pages_language_overlay', + 'pid=' . intval($page_id) . + ' AND ' . $languageClause . + $this->enableFields('pages_language_overlay'), + '', + '', + 2 + ); + if ($noSpecialLanguageRequested) { + // Fetch the row and prefer the most recent in the fallback priority list starting with the lUid + $firstRow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res); + $secondRow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res); + foreach ($languageList as $languageId) { + if ($firstRow['sys_language_uid'] == $languageId) { + $row = $firstRow; + break; + } elseif ($secondRow['sys_language_uid'] == $languageId) { + $row = $secondRow; + break; + } + } + } else { + $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res); + } $GLOBALS['TYPO3_DB']->sql_free_result($res); $this->versionOL('pages_language_overlay', $row); if (is_array($row)) { @@ -394,18 +433,75 @@ class PageRepository { } /** - * Creates language-overlay for records in general (where translation is found - * in records from the same table) + * Creates a language overlay for records stored inside tables which contain the + * translation information themselves. In addition to getRecordOverlay this method + * also checks for specified content language fallbacks and includes them. * * @param string $table Table name - * @param array $row Record to overlay. Must containt uid, pid and $table]['ctrl']['languageField'] - * @param integer $sys_language_content Pointer to the sys_language uid for content on the site. + * @param array $row Record to overlay. Must contain uid, pid and $table]['ctrl']['languageField'] + * @param integer|null $sys_language_content Pointer to the sys_language uid for content on the site. + * @param string|null $OLmode Overlay mode. If "hideNonTranslated" then records without translation will not be returned un-translated but unset (and return value is FALSE) + * @param array|null $fallbackList ordered fallback list of language ids + * @param bool $pageLanguageBinding use page language binding for the language fallback chain (only used if fallbackList is NULL) + * @return mixed Returns the input record, possibly overlaid with a translation. But if $OLmode is "hideNonTranslated" then it will return FALSE if no translation is found. + */ + public function getRecordOverlayWithFallback( + $table, $row, $sys_language_content = NULL, $OLmode = NULL, $fallbackList = NULL, $pageLanguageBinding = TRUE + ) { + /** @var TypoScriptFrontendController $tsfe */ + $tsfe = $GLOBALS['TSFE']; + $sys_language_content = ($sys_language_content !== NULL ? $sys_language_content : $tsfe->sys_language_content); + $OLmode = ($OLmode !== NULL ? $OLmode: $tsfe->sys_language_contentOL); + if ($fallbackList === NULL) { + $fallbackList = $tsfe->languageFallbackChainWithPageLanguageBinding; + if (!$pageLanguageBinding) { + $fallbackList = $tsfe->languageFallbackChain; + } + } + $record = $this->getRecordOverlayWithoutFallback($table, $row, $sys_language_content, $OLmode); + if (!is_array($record) || !isset($record['_LOCALIZED_UID'])) { + if (count($fallbackList) && $sys_language_content && $OLmode !== 'hideNonTranslated') { + foreach ($fallbackList as $fallbackId) { + $record = $this->getRecordOverlayWithoutFallback($table, $row, $fallbackId, $OLmode); + if (is_array($record) && isset($record['_LOCALIZED_UID'])) { + break; + } + } + } + } + return $record; + } + + /** + * Creates a language overlay for records stored inside tables which contain the + * translation information themselves. + * + * @param string $table Table name the record comes from + * @param array $row Record to overlay. Must contain the columns uid, pid and $TCA[$table]['ctrl']['languageField'] + * @param integer $sys_language_content Pointer to the sys_language uid to use for content. * @param string $OLmode Overlay mode. If "hideNonTranslated" then records without translation will not be returned un-translated but unset (and return value is FALSE) * @throws \UnexpectedValueException * @return mixed Returns the input record, possibly overlaid with a translation. But if $OLmode is "hideNonTranslated" then it will return FALSE if no translation is found. * @todo Define visibility + * @deprecated since 6.2; will be removed two versions later */ public function getRecordOverlay($table, $row, $sys_language_content, $OLmode = '') { + GeneralUtility::logDeprecatedFunction(); + return $this->getRecordOverlayWithoutFallback($table, $row, $sys_language_content, $OLmode); + } + + /** + * Creates a language overlay for records stored inside tables which contain the + * translation information themselves. + * + * @throws \UnexpectedValueException + * @param string $table Table name the record comes from + * @param array $row Record to overlay. Must contain the columns uid, pid and $TCA[$table]['ctrl']['languageField'] + * @param integer $sys_language_content Pointer to the sys_language uid to use for content. + * @param string $OLmode Overlay mode. If "hideNonTranslated" then records without translation will not be returned translated but unset (and return value is FALSE) + * @return mixed Returns the input record, possibly overlaid with a translation. But if $OLmode is "hideNonTranslated" then it will return FALSE if no translation is found. + */ + public function getRecordOverlayWithoutFallback($table, $row, $sys_language_content, $OLmode) { if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_page.php']['getRecordOverlay'])) { foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_page.php']['getRecordOverlay'] as $classRef) { $hookObject = GeneralUtility::getUserObj($classRef); diff --git a/typo3/sysext/frontend/Tests/Unit/ContentObject/Menu/AbstractMenuContentObjectTest.php b/typo3/sysext/frontend/Tests/Unit/ContentObject/Menu/AbstractMenuContentObjectTest.php index b97d23e..c2cd160 100644 --- a/typo3/sysext/frontend/Tests/Unit/ContentObject/Menu/AbstractMenuContentObjectTest.php +++ b/typo3/sysext/frontend/Tests/Unit/ContentObject/Menu/AbstractMenuContentObjectTest.php @@ -92,7 +92,7 @@ class AbstractMenuContentObjectTest extends \TYPO3\CMS\Core\Tests\UnitTestCase { $this->fixture->sys_page->expects($this->once())->method('getPage')->will($this->returnValue(array('_PAGES_OVERLAY_LANGUAGE' => 1))); $this->fixture->parent_cObj->expects($this->once())->method('exec_getQuery')->will($this->returnValue(1)); $GLOBALS['TYPO3_DB']->expects($this->exactly(2))->method('sql_fetch_assoc')->will($this->onConsecutiveCalls($this->returnValue(array('uid' => 0, 'header' => 'NOT_OVERLAID')), $this->returnValue(FALSE))); - $this->fixture->sys_page->expects($this->once())->method('getRecordOverlay')->will($this->returnValue(array('uid' => 0, 'header' => 'OVERLAID'))); + $this->fixture->sys_page->expects($this->once())->method('getRecordOverlayWithFallback')->will($this->returnValue(array('uid' => 0, 'header' => 'OVERLAID'))); $result = $this->fixture->_call('sectionIndex', 'field'); $this->assertEquals($result[0]['title'], 'OVERLAID'); } diff --git a/typo3/sysext/t3editor/res/tsref/tsref.xml b/typo3/sysext/t3editor/res/tsref/tsref.xml index d104d2d..941dcdc 100644 --- a/typo3/sysext/t3editor/res/tsref/tsref.xml +++ b/typo3/sysext/t3editor/res/tsref/tsref.xml @@ -1002,6 +1002,11 @@ ignore - The system will stay with the selected language even if the page is not + + + + + + + + + + + + @@ -5536,6 +5549,14 @@ All measures is in pixels.]]> + + + + + + + +