Commit 12b9bfcf authored by Johannes Schlier's avatar Johannes Schlier Committed by Benni Mack
Browse files

[BUGFIX] Fix select with multiple enabled not being saved correctly

If the 'multiple' field in the fieldConfig is set the
$newDatabaseValueArray is returned as is, with duplicate entries. If this
is not the case $newDatabaseValueArray is returned as before, being
modified with the array_unique function.

Resolves: #76918
Releases: master, 7.6
Change-Id: Id8ddac95162a929aeb1b5d7bae33a460317b46cb
Reviewed-on: https://review.typo3.org/49981


Tested-by: default avatarTYPO3com <no-reply@typo3.com>
Reviewed-by: Markus Klein's avatarMarkus Klein <markus.klein@typo3.org>
Reviewed-by: Karol Lamparski's avatarKarol Lamparski <klamparski@gmail.com>
Tested-by: Karol Lamparski's avatarKarol Lamparski <klamparski@gmail.com>
Reviewed-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
Tested-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
parent 1c38554b
...@@ -1202,6 +1202,9 @@ abstract class AbstractItemProvider ...@@ -1202,6 +1202,9 @@ abstract class AbstractItemProvider
$newDatabaseValueArray = array_merge($newDatabaseValueArray, $relationHandler->getValueArray()); $newDatabaseValueArray = array_merge($newDatabaseValueArray, $relationHandler->getValueArray());
} }
if ($fieldConfig['config']['multiple']) {
return $newDatabaseValueArray;
}
return array_unique($newDatabaseValueArray); return array_unique($newDatabaseValueArray);
} }
......
...@@ -3187,6 +3187,97 @@ class TcaSelectItemsTest extends UnitTestCase ...@@ -3187,6 +3187,97 @@ class TcaSelectItemsTest extends UnitTestCase
$this->assertEquals($expected, $this->subject->addData($input)); $this->assertEquals($expected, $this->subject->addData($input));
} }
/**
* @test
*/
public function processSelectFieldValueReturnsDuplicateValuesForMultipleSelect()
{
$languageService = $this->prophesize(LanguageService::class);
$GLOBALS['LANG'] = $languageService->reveal();
$languageService->sL(Argument::cetera())->willReturnArgument(0);
$input = [
'tableName' => 'aTable',
'databaseRow' => [
'aField' => '1,foo,foo,2,bar',
],
'processedTca' => [
'columns' => [
'aField' => [
'config' => [
'type' => 'select',
'renderType' => 'selectSingle',
'multiple' => true,
'maxitems' => 999,
'items' => [
['1', '1', null, null],
['foo', 'foo', null, null],
['bar', 'bar', null, null],
['2', '2', null, null],
],
],
],
],
],
];
$expected = $input;
$expected['databaseRow']['aField'] = [
'1',
'foo',
'foo',
'2',
'bar'
];
$this->assertEquals($expected, $this->subject->addData($input));
}
/**
* @test
*/
public function processSelectFieldValueReturnsUniqueValuesForMultipleSelect()
{
$languageService = $this->prophesize(LanguageService::class);
$GLOBALS['LANG'] = $languageService->reveal();
$languageService->sL(Argument::cetera())->willReturnArgument(0);
$input = [
'tableName' => 'aTable',
'databaseRow' => [
'aField' => '1,foo,foo,2,bar',
],
'processedTca' => [
'columns' => [
'aField' => [
'config' => [
'type' => 'select',
'renderType' => 'selectSingle',
'multiple' => false,
'maxitems' => 999,
'items' => [
['1', '1', null, null],
['foo', 'foo', null, null],
['bar', 'bar', null, null],
['2', '2', null, null],
],
],
],
],
],
];
$expected = $input;
$expected['databaseRow']['aField'] = [
0 => '1',
1 => 'foo',
3 => '2',
4 => 'bar',
];
$this->assertEquals($expected, $this->subject->addData($input));
}
/** /**
* Data Provider * Data Provider
* *
......
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