Commit 12da9f62 authored by André Buchmann's avatar André Buchmann Committed by Benni Mack
Browse files

[BUGFIX] Apply empty values in language-overlay

Some default fields (e.g. tt_content.bodytext) can contain null values.
TYPO3 first fetches the data in the default language and then overlays
the rows data with the translation values. The overlay method inspects
each array item with the php isset() function. This validates not only
the existence of the array key, but also the values. null and
false values evaluated as false. Empty strings evaluate as true.
This leads to inconsistent output in the frontend.

The overlay now valides only the array key existence and applies also
empty values.

Resolves: #97616
Releases: main, 11.5, 10.4
Change-Id: I4b01c52e9ac7adde786b3395bce870bc0a354b58
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/74632


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>
Reviewed-by: Oliver Bartsch's avatarOliver Bartsch <bo@cedev.de>
Reviewed-by: Oliver Klee's avatarOliver Klee <typo3-coding@oliverklee.de>
Reviewed-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
parent d1206ba2
......@@ -690,7 +690,7 @@ class PageRepository implements LoggerAwareInterface
$row['_ORIG_pid'] = $olrow['_ORIG_pid'];
}
foreach ($row as $fN => $fV) {
if ($fN !== 'uid' && $fN !== 'pid' && isset($olrow[$fN])) {
if ($fN !== 'uid' && $fN !== 'pid' && array_key_exists($fN, $olrow)) {
$row[$fN] = $olrow[$fN];
} elseif ($fN === 'uid') {
$row['_LOCALIZED_UID'] = $olrow['uid'];
......
......@@ -681,4 +681,25 @@ class PageRepositoryTest extends FunctionalTestCase
$result = $subject->getDescendantPageIdsRecursive(1, 2, bypassEnableFieldsCheck:true);
self::assertEquals([2, 5, 6, 7, 3, 8, 9, 4, 10], $result);
}
/**
* @test
*/
public function getLanguageOverlayResolvesContentWithNullInValues(): void
{
$context = new Context();
$context->setAspect('language', new LanguageAspect(1, 1, LanguageAspect::OVERLAYS_ON_WITH_FLOATING, [0]));
$subject = new PageRepository($context);
$record = $subject->getRawRecord('tt_content', 1);
self::assertSame('Default Content #1', $record['header']);
$overlaidRecord = $subject->getLanguageOverlay('tt_content', $record);
self::assertSame(2, $overlaidRecord['_LOCALIZED_UID']);
self::assertSame('Translated Content #1', $overlaidRecord['header']);
// Check if "bodytext" is actually overlaid with a NULL value
$record = $subject->getRawRecord('tt_content', 3);
$overlaidRecord = $subject->getLanguageOverlay('tt_content', $record);
self::assertSame('Translated #2', $overlaidRecord['header']);
self::assertNull($overlaidRecord['bodytext']);
}
}
......@@ -22,3 +22,9 @@ pages,,,,,,,,,,,,,,,,
,1002,1000,root translation,0,,0,0,0,0,0,1,1001,1,0,0,32
,1003,1000,Mount default language,0,,0,0,0,0,0,0,0,7,1001,1,64
,1004,1000,Mount translation,0,,0,0,0,0,0,1,1003,7,1001,1,64
tt_content,,,,,,,,,,,,,,,,
,uid,pid,header,bodytext,sys_language_uid,l18n_parent,,,,,,,,,,
,1,1,"Default Content #1","<p>Say thanks for HTML in the DB</p>",0,0,,,,,,,,,,
,2,1,"Translated Content #1","<p>Grazie por HTML en la database</p>",1,1,,,,,,,,,,
,3,1,"Default Content #2","<p>Could be anything</p>",0,0,,,,,,,,,,
,4,1,"Translated #2","\NULL",1,3,,,,,,,,,,
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