Skip to content
Snippets Groups Projects
Commit f7a1b5e0 authored by Markus Klein's avatar Markus Klein Committed by Oliver Bartsch
Browse files

[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: default avatarcore-ci <typo3@b13.com>
Tested-by: default avatarJosef Glatz <typo3@josefglatz.at>
Tested-by: default avatarOliver Bartsch <bo@cedev.de>
Reviewed-by: default avatarOliver Bartsch <bo@cedev.de>
Reviewed-by: default avatarJosef Glatz <typo3@josefglatz.at>
parent d73ae943
Branches
Tags
No related merge requests found
......@@ -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;
......
......@@ -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.',
......
......@@ -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]
......
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