Skip to content
Snippets Groups Projects
Commit a2e97ec7 authored by Oliver Bartsch's avatar Oliver Bartsch Committed by Christian Kuhn
Browse files

[BUGFIX] Properly set columnMap relation for type "folder"

TCA type "folder" is a special type since it's always
a relation but not to a table but one or more folder
identifier. This is now handled properly.

In previous versions, this was handled (by accident?)
since the $type (the FQN) matched a strpbrk() check,
which led to marking the relation as "toOne".

Resolves: #105317
Releases: main, 13.4
Change-Id: Ib5e1e5f1762801b43c619bd1fe9a95b3339f8ffa
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/86682


Reviewed-by: default avatarBenni Mack <benni@typo3.org>
Tested-by: default avatarcore-ci <typo3@b13.com>
Tested-by: default avatarChristian Kuhn <lolli@schwarzbu.ch>
Tested-by: default avatarBenni Mack <benni@typo3.org>
Reviewed-by: default avatarChristian Kuhn <lolli@schwarzbu.ch>
parent 94cbd224
No related branches found
No related tags found
No related merge requests found
......@@ -78,11 +78,18 @@ readonly class ColumnMapFactory
protected function setRelations(ColumnMap $columnMap, FieldTypeInterface $field, ?string $type, ?string $elementType): ColumnMap
{
$columnConfiguration = $field->getConfiguration();
if ($field instanceof FolderFieldType
&& !in_array((string)($columnConfiguration['relationship'] ?? ''), ['oneToOne', 'manyToOne'], true)
&& (!isset($columnConfiguration['maxitems']) || $columnConfiguration['maxitems'] > 1)
) {
$columnMap->setTypeOfRelation(Relation::HAS_MANY);
if ($field instanceof FolderFieldType) {
// Folder is a special case which always has a relation to one or many "folders".
// In case "maxitems" is set to > 1 and relationship is not explicitly set to "*toOne"
// it's HAS_MANY, in all other cases it's HAS_ONE. It can never belong to many.
// @todo we should get rid of the "maxitems" and rely purely on the evaluated relationship type
if (!in_array((string)($columnConfiguration['relationship'] ?? ''), ['oneToOne', 'manyToOne'], true)
&& (!isset($columnConfiguration['maxitems']) || $columnConfiguration['maxitems'] > 1)
) {
$columnMap->setTypeOfRelation(Relation::HAS_MANY);
} else {
$columnMap->setTypeOfRelation(Relation::HAS_ONE);
}
return $columnMap;
}
......
......@@ -231,9 +231,6 @@ final class ColumnMapFactoryTest extends FunctionalTestCase
{
$columnName = 'folder';
$propertyName = GeneralUtility::underscoredToLowerCamelCase($columnName);
$expectedColumnMap = new ColumnMap($columnName);
$expectedColumnMap->setType(TableColumnType::FOLDER);
$expectedColumnMap->setTypeOfRelation(Relation::HAS_MANY);
yield 'columns configuration is initialized for type folder' => [
'columnName' => $columnName,
'columnConfiguration' => [
......@@ -242,14 +239,86 @@ final class ColumnMapFactoryTest extends FunctionalTestCase
],
],
'propertyName' => $propertyName,
'expectedColumnMap' => $expectedColumnMap,
'expectedRelationType' => Relation::HAS_MANY,
];
yield 'folder with maxitems > 1' => [
'columnName' => $columnName,
'columnConfiguration' => [
'config' => [
'type' => 'folder',
'maxitems' => 5,
],
],
'propertyName' => $propertyName,
'expectedRelationType' => Relation::HAS_MANY,
];
yield 'folder with maxitems = 1' => [
'columnName' => $columnName,
'columnConfiguration' => [
'config' => [
'type' => 'folder',
'maxitems' => 1,
],
],
'propertyName' => $propertyName,
'expectedRelationType' => Relation::HAS_ONE,
];
yield 'folder with relationship = oneToOne' => [
'columnName' => $columnName,
'columnConfiguration' => [
'config' => [
'type' => 'folder',
'relationship' => 'oneToOne',
'maxitems' => 5,
],
],
'propertyName' => $propertyName,
'expectedRelationType' => Relation::HAS_ONE,
];
yield 'folder with relationship = manyToOne' => [
'columnName' => $columnName,
'columnConfiguration' => [
'config' => [
'type' => 'folder',
'relationship' => 'manyToOne',
'maxitems' => 5,
],
],
'propertyName' => $propertyName,
'expectedRelationType' => Relation::HAS_ONE,
];
yield 'folder with relationship = manyToMany and maxitems = 1' => [
'columnName' => $columnName,
'columnConfiguration' => [
'config' => [
'type' => 'folder',
'relationship' => 'manyToMany', // invalid for this type
'maxitems' => 1,
],
],
'propertyName' => $propertyName,
'expectedRelationType' => Relation::HAS_ONE,
];
yield 'folder with relationship = manyToMany' => [
'columnName' => $columnName,
'columnConfiguration' => [
'config' => [
'type' => 'folder',
'relationship' => 'manyToMany', // invalid for this type
],
],
'propertyName' => $propertyName,
'expectedRelationType' => Relation::HAS_MANY,
];
}
#[DataProvider('createWithFolderTypeDataProvider')]
#[Test]
public function createWithFolderType(string $columnName, array $columnConfiguration, string $propertyName, ColumnMap $expectedColumnMap): void
public function createWithFolderType(string $columnName, array $columnConfiguration, string $propertyName, Relation $expectedRelationType): void
{
$expectedColumnMap = new ColumnMap($columnName);
$expectedColumnMap->setType(TableColumnType::FOLDER);
$expectedColumnMap->setTypeOfRelation($expectedRelationType);
self::assertEquals(
$expectedColumnMap,
$this->columnMapFactory->create($this->fieldTypeFactory->createFieldType($columnName, $columnConfiguration, 'virtual', new RelationMap()), $propertyName, ColumnMapFactoryEntityFixture::class)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment