From f7a1b5e07dc8f8fbf3c8ae558340cf526cc056ec Mon Sep 17 00:00:00 2001 From: Markus Klein <markus.klein@typo3.org> Date: Fri, 23 Feb 2024 14:53:05 +0100 Subject: [PATCH] [BUGFIX] Allow maxitems=1 for TCA type category In relation mode "manyToMany" it is okay to have a limit of one. Code-wise the FlexForm code is slightly simplified as there is no support for the "manytoMany" case. Resolves: #103188 Releases: main, 12.4, 11.5 Change-Id: Ib2bbafadefc39f603a9ec4fda20aebcee85cdd7a Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/83090 Tested-by: core-ci <typo3@b13.com> Tested-by: Josef Glatz <typo3@josefglatz.at> Tested-by: Oliver Bartsch <bo@cedev.de> Reviewed-by: Oliver Bartsch <bo@cedev.de> Reviewed-by: Josef Glatz <typo3@josefglatz.at> --- .../Configuration/FlexForm/FlexFormTools.php | 2 +- .../Configuration/Tca/TcaPreparation.php | 4 ++- .../Configuration/Tca/TcaPreparationTest.php | 31 ------------------- 3 files changed, 4 insertions(+), 33 deletions(-) diff --git a/typo3/sysext/core/Classes/Configuration/FlexForm/FlexFormTools.php b/typo3/sysext/core/Classes/Configuration/FlexForm/FlexFormTools.php index 2d18336e93fb..9c2830591ffa 100644 --- a/typo3/sysext/core/Classes/Configuration/FlexForm/FlexFormTools.php +++ b/typo3/sysext/core/Classes/Configuration/FlexForm/FlexFormTools.php @@ -654,7 +654,7 @@ class FlexFormTools ); } $fieldConfig['config']['maxitems'] = 1; - } elseif ($fieldConfig['config']['relationship'] === 'oneToMany') { + } else { // In case maxitems is not set or set to 0, set the default value "99999" if (!($fieldConfig['config']['maxitems'] ?? false)) { $fieldConfig['config']['maxitems'] = 99999; diff --git a/typo3/sysext/core/Classes/Configuration/Tca/TcaPreparation.php b/typo3/sysext/core/Classes/Configuration/Tca/TcaPreparation.php index 3f5ca9f2a749..e47eb0969512 100644 --- a/typo3/sysext/core/Classes/Configuration/Tca/TcaPreparation.php +++ b/typo3/sysext/core/Classes/Configuration/Tca/TcaPreparation.php @@ -116,7 +116,9 @@ class TcaPreparation } elseif (!($fieldConfig['config']['maxitems'] ?? false)) { // In case maxitems is not set or set to 0, set the default value "99999" $fieldConfig['config']['maxitems'] = 99999; - } elseif ((int)($fieldConfig['config']['maxitems'] ?? 0) === 1) { + } elseif ($fieldConfig['config']['relationship'] === 'oneToMany' + && (int)($fieldConfig['config']['maxitems'] ?? 0) === 1 + ) { throw new \RuntimeException( $fieldName . ' of table ' . $table . ' is defined as type category with a ' . $fieldConfig['config']['relationship'] . ' relationship. Therefore, maxitems can not be set to 1. Use oneToOne as relationship instead.', diff --git a/typo3/sysext/core/Tests/Unit/Configuration/Tca/TcaPreparationTest.php b/typo3/sysext/core/Tests/Unit/Configuration/Tca/TcaPreparationTest.php index 72c4f14f5b6f..c9214c653dc8 100644 --- a/typo3/sysext/core/Tests/Unit/Configuration/Tca/TcaPreparationTest.php +++ b/typo3/sysext/core/Tests/Unit/Configuration/Tca/TcaPreparationTest.php @@ -251,21 +251,6 @@ final class TcaPreparationTest extends UnitTestCase public static function configureCategoryRelationsThrowsExceptionOnInvalidMaxitemsDataProvider(): \Generator { - yield 'No relationship with maxitems=1 (falls back to manyToMany)' => [ - [ - 'aTable' => [ - 'columns' => [ - 'foo' => [ - 'config' => [ - 'type' => 'category', - 'maxitems' => 1, - ], - ], - ], - ], - ], - 1627335017, - ]; yield 'oneToOne relationship with maxitems=2' => [ [ 'aTable' => [ @@ -298,22 +283,6 @@ final class TcaPreparationTest extends UnitTestCase ], 1627335017, ]; - yield 'manyToMany relationship with maxitems=1' => [ - [ - 'aTable' => [ - 'columns' => [ - 'foo' => [ - 'config' => [ - 'type' => 'category', - 'relationship' => 'oneToMany', - 'maxitems' => 1, - ], - ], - ], - ], - ], - 1627335017, - ]; } #[Test] -- GitLab