Skip to content

Commit

Permalink
[BUGFIX] Allow maxitems=1 for TCA type category
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
liayn authored and o-ba committed Feb 28, 2024
1 parent d73ae94 commit f7a1b5e
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ protected function prepareCategoryFields(array $dataStructureSheets): array
);
}
$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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,9 @@ protected function configureCategoryRelations(array $tca): array
} 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.',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,21 +251,6 @@ public function configureCategoryRelationsThrowsExceptionOnInvalidMaxitems(array

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' => [
Expand Down Expand Up @@ -298,22 +283,6 @@ public static function configureCategoryRelationsThrowsExceptionOnInvalidMaxitem
],
1627335017,
];
yield 'manyToMany relationship with maxitems=1' => [
[
'aTable' => [
'columns' => [
'foo' => [
'config' => [
'type' => 'category',
'relationship' => 'oneToMany',
'maxitems' => 1,
],
],
],
],
],
1627335017,
];
}

#[Test]
Expand Down

0 comments on commit f7a1b5e

Please sign in to comment.