Skip to content

Commit

Permalink
[BUGFIX] Apply empty values in language-overlay
Browse files Browse the repository at this point in the history
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/+/74837
Tested-by: André Buchmann <andy.schliesser@gmail.com>
Tested-by: core-ci <typo3@b13.com>
Tested-by: Benni Mack <benni@typo3.org>
Reviewed-by: André Buchmann <andy.schliesser@gmail.com>
Reviewed-by: Oliver Klee <typo3-coding@oliverklee.de>
Reviewed-by: Benni Mack <benni@typo3.org>
  • Loading branch information
André Buchmann authored and bmack committed Jun 14, 2022
1 parent 300531f commit cb1d82f
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 1 deletion.
Expand Up @@ -661,7 +661,7 @@ public function getRecordOverlay($table, $row, $sys_language_content, $OLmode =
$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'];
Expand Down
Expand Up @@ -611,4 +611,25 @@ protected function assertNotOverlayRow($row)
self::assertFalse(isset($row['_PAGES_OVERLAY_UID']));
self::assertFalse(isset($row['_PAGES_OVERLAY_LANGUAGE']));
}

/**
* @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, (int)$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']);
}
}
31 changes: 31 additions & 0 deletions typo3/sysext/core/Tests/Functional/Fixtures/pages.xml
Expand Up @@ -184,4 +184,35 @@
<sys_language_uid>1</sys_language_uid>
<title>Mount translation</title>
</pages>
<tt_content>
<uid>1</uid>
<pid>1</pid>
<header>Default Content #1</header>
<bodytext><p>Say thanks for HTML in the DB</p></bodytext>
<sys_language_uid>0</sys_language_uid>
<l18n_parent>0</l18n_parent>
</tt_content>
<tt_content>
<uid>2</uid>
<pid>1</pid>
<header>Translated Content #1</header>
<bodytext><p>Grazie por HTML en la database</p></bodytext>
<sys_language_uid>1</sys_language_uid>
<l18n_parent>1</l18n_parent>
</tt_content>
<tt_content>
<uid>3</uid>
<pid>1</pid>
<header>Default Content #2</header>
<bodytext><p>Could be anything</p></bodytext>
<sys_language_uid>0</sys_language_uid>
<l18n_parent>0</l18n_parent>
</tt_content>
<tt_content>
<uid>4</uid>
<pid>1</pid>
<header>Translated #2</header>
<sys_language_uid>1</sys_language_uid>
<l18n_parent>3</l18n_parent>
</tt_content>
</dataset>

0 comments on commit cb1d82f

Please sign in to comment.