[BUGFIX] Fix select with multiple enabled not being saved correctly 81/49981/6
authorJohannes Schlier <johannes.schlier@b13.de>
Tue, 20 Sep 2016 15:21:50 +0000 (17:21 +0200)
committerBenni Mack <benni@typo3.org>
Sat, 8 Oct 2016 18:41:46 +0000 (20:41 +0200)
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: TYPO3com <no-reply@typo3.com>
Reviewed-by: Markus Klein <markus.klein@typo3.org>
Reviewed-by: Karol Lamparski <klamparski@gmail.com>
Tested-by: Karol Lamparski <klamparski@gmail.com>
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
typo3/sysext/backend/Classes/Form/FormDataProvider/AbstractItemProvider.php
typo3/sysext/backend/Tests/Unit/Form/FormDataProvider/TcaSelectItemsTest.php

index f1269d6..2cc31e4 100644 (file)
@@ -1202,6 +1202,9 @@ abstract class AbstractItemProvider
             $newDatabaseValueArray = array_merge($newDatabaseValueArray, $relationHandler->getValueArray());
         }
 
+        if ($fieldConfig['config']['multiple']) {
+            return $newDatabaseValueArray;
+        }
         return array_unique($newDatabaseValueArray);
     }
 
index d94d821..35ce77c 100644 (file)
@@ -3188,6 +3188,97 @@ class TcaSelectItemsTest extends UnitTestCase
     }
 
     /**
+     * @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
      *
      * @return array