diff --git a/typo3/sysext/backend/Classes/Form/Element/SelectTreeElement.php b/typo3/sysext/backend/Classes/Form/Element/SelectTreeElement.php index d3464f3e11ce74b0a7dfca100abc8740dd509458..e28b012914ddbced2b17ecba51c8138c866b4b6f 100644 --- a/typo3/sysext/backend/Classes/Form/Element/SelectTreeElement.php +++ b/typo3/sysext/backend/Classes/Form/Element/SelectTreeElement.php @@ -46,9 +46,6 @@ class SelectTreeElement extends AbstractFormElement { $possibleSelectboxItems = $config['items']; $selectedNodes = $parameterArray['itemFormElValue']; - if ($config['maxitems'] === 1 && count($selectedNodes) === 1 && empty($selectedNodes[0])) { - $selectedNodes = array(); - } $selectedNodesForApi = array(); foreach ($selectedNodes as $selectedNode) { diff --git a/typo3/sysext/backend/Classes/Form/FormDataProvider/TcaSelectItems.php b/typo3/sysext/backend/Classes/Form/FormDataProvider/TcaSelectItems.php index 8619ed82da6422ea32520856824717ddc2ba00f2..cf62162206d8bf63d0191bac86af3e50ef530d01 100644 --- a/typo3/sysext/backend/Classes/Form/FormDataProvider/TcaSelectItems.php +++ b/typo3/sysext/backend/Classes/Form/FormDataProvider/TcaSelectItems.php @@ -1005,7 +1005,7 @@ class TcaSelectItems extends AbstractItemProvider implements FormDataProviderInt // will take care of showing the "Invalid value" text. // For maxitems=1 select fields is is also possible to select empty values. // @todo: move handling of invalid values to this data provider. - if ($fieldConfig['config']['maxitems'] === 1) { + if ($fieldConfig['config']['maxitems'] === 1 && empty($fieldConfig['config']['MM'])) { return array($result['databaseRow'][$fieldName]); } diff --git a/typo3/sysext/backend/Tests/Unit/Form/FormDataProvider/TcaSelectItemsTest.php b/typo3/sysext/backend/Tests/Unit/Form/FormDataProvider/TcaSelectItemsTest.php index d500c2c3c7e9860041c318a7cad2bc8fee428da2..fc3d5822a9a4f02d16b578c47bb690f03e0e3a9f 100644 --- a/typo3/sysext/backend/Tests/Unit/Form/FormDataProvider/TcaSelectItemsTest.php +++ b/typo3/sysext/backend/Tests/Unit/Form/FormDataProvider/TcaSelectItemsTest.php @@ -2424,4 +2424,100 @@ class TcaSelectItemsTest extends UnitTestCase { $this->assertEquals($expected, $this->subject->addData($input)); } + + /** + * @test + * @dataProvider correctValuesForMmRelationWithSingleValueAllowedDataProvider + */ + public function correctValuesForMmRelationWithSingleValueAllowed($input, $relationHandlerUids) { + + $GLOBALS['TCA']['foreignTable'] = []; + + /** @var BackendUserAuthentication|ObjectProphecy $backendUserProphecy */ + $backendUserProphecy = $this->prophesize(BackendUserAuthentication::class); + $GLOBALS['BE_USER'] = $backendUserProphecy->reveal(); + + /** @var DatabaseConnection|ObjectProphecy $database */ + $database = $this->prophesize(DatabaseConnection::class); + $GLOBALS['TYPO3_DB'] = $database->reveal(); + + $fieldConfig = $input['processedTca']['columns']['aField']['config']; + /** @var RelationHandler|ObjectProphecy $relationHandlerProphecy */ + $relationHandlerProphecy = $this->prophesize(RelationHandler::class); + GeneralUtility::addInstance(RelationHandler::class, $relationHandlerProphecy->reveal()); + + $field = $input['databaseRow']['aField']; + $foreignTable = $input['processedTca']['columns']['aField']['config']['foreign_table']; + $mmTable = $input['processedTca']['columns']['aField']['config']['MM']; + $uid = $input['databaseRow']['uid']; + $tableName = $input['tableName']; + $fieldConfig = $input['processedTca']['columns']['aField']['config']; + + $relationHandlerProphecy->start($field, $foreignTable, $mmTable, $uid, $tableName, $fieldConfig)->shouldBeCalled(); + $relationHandlerProphecy->getValueArray()->shouldBeCalled()->willReturn($relationHandlerUids); + + $expected = $input; + $expected['databaseRow']['aField'] = $relationHandlerUids; + + $this->assertEquals($expected, $this->subject->addData($input)); + } + + /** + * Data Provider + */ + public function correctValuesForMmRelationWithSingleValueAllowedDataProvider() { + return array( + 'Relation with MM table and maxitems = 1 processes field value (item count)' => [ + [ + 'tableName' => 'aTable', + 'databaseRow' => [ + 'uid' => 42, + // MM relation with one item has 1 in field value + 'aField' => 1, + ], + 'processedTca' => [ + 'columns' => [ + 'aField' => [ + 'config' => [ + 'type' => 'select', + 'maxitems' => 1, + 'MM' => 'mm_aTable_foreignTable', + 'foreign_table' => 'foreignTable', + 'items' => [], + ], + ], + ], + ], + ], + [ + 24 + ] + ], + 'Relation with MM table and maxitems = 1 results in empty array if no items are set' => [ + [ + 'tableName' => 'aTable', + 'databaseRow' => [ + 'uid' => 58, + // MM relation with no items has 0 in field value + 'aField' => 0, + ], + 'processedTca' => [ + 'columns' => [ + 'aField' => [ + 'config' => [ + 'type' => 'select', + 'maxitems' => 1, + 'MM' => 'mm_aTable_foreignTable', + 'foreign_table' => 'foreignTable', + 'items' => [], + ], + ], + ], + ], + ], + [ + ] + ] + ); + } }