Commit e5d157de authored by Johannes Schlier's avatar Johannes Schlier Committed by Oliver Hader
Browse files

[BUGFIX] Handle null values correctly to avoid PHP errors

The new RteHtmlParser->transformTextForPersistence() method
expects a string value. Before this patch the given value
was simply passed without checking its type or casting it.

However, if "null" is handed in (by e.g. a translated record which
expects null), null is now kept.

Resolves: #91749
Releases: master, 10.4
Change-Id: I9db872ca73dcf2bbfc2ac2d0b67d45ca3ffd4c5e
parent 8788b9ce
......@@ -1809,12 +1809,16 @@ class DataHandler implements LoggerAwareInterface
if ($this->dontProcessTransformations) {
return $valueArray;
}
// Keep null as value
if ($value === null) {
return $valueArray;
}
if (isset($tcaFieldConf['enableRichtext']) && (bool)$tcaFieldConf['enableRichtext'] === true) {
$recordType = BackendUtility::getTCAtypeValue($table, $this->checkValue_currentRecord);
$richtextConfigurationProvider = GeneralUtility::makeInstance(Richtext::class);
$richtextConfiguration = $richtextConfigurationProvider->getConfiguration($table, $field, $realPid, $recordType, $tcaFieldConf);
$rteParser = GeneralUtility::makeInstance(RteHtmlParser::class);
$valueArray['value'] = $rteParser->transformTextForPersistence($value, $richtextConfiguration['proc.'] ?? []);
$valueArray['value'] = $rteParser->transformTextForPersistence((string)$value, $richtextConfiguration['proc.'] ?? []);
}
return $valueArray;
......
......@@ -145,4 +145,23 @@ TCAdefaults.tt_content.header = local space
$newContentRecord = BackendUtility::getRecord('tt_content', $newContentId);
self::assertEquals($newContentRecord['header'], 'local space');
}
/**
* @test
*/
public function defaultValueForNullTextfieldsIsConsidered(): void
{
// New content element without bodytext
$GLOBALS['TCA']['tt_content']['columns']['bodytext']['l10n_mode'] = 'exclude';
$GLOBALS['TCA']['tt_content']['columns']['bodytext']['config']['enableRichtext'] = true;
$map = $this->actionService->createNewRecord('tt_content', self::PAGE_DATAHANDLER, [
'header' => 'Random header',
'bodytext' => null
]);
$newContentId = reset($map['tt_content']);
$map = $this->actionService->localizeRecord('tt_content', $newContentId, 1);
$translatedContentId = reset($map['tt_content']);
$newContentRecord = BackendUtility::getRecord('tt_content', $translatedContentId);
self::assertNull($newContentRecord['bodytext']);
}
}
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