Skip to content

Commit

Permalink
[BUGFIX] Ensure items array in DataHandler checkValue methods
Browse files Browse the repository at this point in the history
It is possible that TCA items array is not set in DataHandler if

1. items is defined through types/*/columnsOverrides
2. DataHandler is triggered with context of another record type
   (e.g. by a translation request)

This patch ensures we are always dealing with an array for items. Also,
when passing it as parameter to
`ItemProcessingService->getProcessingItems`.

Resolves: #103472
Releases: main, 12.4
Change-Id: I364841982b7c2913e339bf5a504d811b3e050049
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/83575
Tested-by: core-ci <typo3@b13.com>
Tested-by: Stefan Bürk <stefan@buerk.tech>
Reviewed-by: Nikita Hovratov <nikita.h@live.de>
Reviewed-by: Oliver Klee <typo3-coding@oliverklee.de>
Tested-by: Nikita Hovratov <nikita.h@live.de>
Tested-by: Oliver Klee <typo3-coding@oliverklee.de>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Stefan Bürk <stefan@buerk.tech>
  • Loading branch information
nhovratov committed Apr 23, 2024
1 parent 04b43e4 commit db6df19
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
15 changes: 8 additions & 7 deletions typo3/sysext/core/Classes/DataHandling/DataHandler.php
Expand Up @@ -2245,14 +2245,15 @@ protected function checkValueForCheck($res, $value, $tcaFieldConf, $table, $id,
* @param string $field The field to check
* @return array Modified $res array
*/
protected function checkValueForRadio($res, $value, $tcaFieldConf, $table, $id, $pid, $field)
protected function checkValueForRadio(array $res, $value, $tcaFieldConf, $table, $id, $pid, $field): array
{
if (is_array($tcaFieldConf['items'])) {
foreach ($tcaFieldConf['items'] as $set) {
if ((string)$set['value'] === (string)$value) {
$res['value'] = $value;
break;
}
if (!is_array($tcaFieldConf['items'] ?? null)) {
$tcaFieldConf['items'] = [];
}
foreach ($tcaFieldConf['items'] as $set) {
if ((string)$set['value'] === (string)$value) {
$res['value'] = $value;
break;
}
}

Expand Down
10 changes: 10 additions & 0 deletions typo3/sysext/core/Tests/Unit/DataHandling/DataHandlerTest.php
Expand Up @@ -1086,6 +1086,16 @@ public function checkValue_checkReturnsExpectedValues(string|int $value, string|
self::assertSame($expectedResult, $this->subject->_call('checkValueForCheck', $result, $value, $tcaFieldConfiguration, '', 0, 0, ''));
}

#[Test]
public function checkValueForRadioAcceptsUndefinedItems(): void
{
$expectedResult = [];
$tcaConfig = [];
$value = 0;
$result = $this->subject->_call('checkValueForRadio', [], $value, $tcaConfig, '', 0, 0, '');
self::assertSame($expectedResult, $result);
}

#[Test]
public function checkValueForInputConvertsNullToEmptyString(): void
{
Expand Down

0 comments on commit db6df19

Please sign in to comment.