Commit f1b4f90e authored by Andreas Fernandez's avatar Andreas Fernandez
Browse files

[BUGFIX] Allow CSV in startingPoints config as advertised

The category starting points introduced with #95037 were designed to
allow comma-separated values in its configuration. Due to improper
tests, this specific notation was not discovered as being broken right
now.

If the incoming configuration is a string, GeneralUtility::intExplode()
is applied to remove any non-integer value. Afterwards, a new CSV
string is generated.

Resolves: #96397
Related: #95037
Releases: main, 11.5
Change-Id: I0759d8093bb4665b7709f4e20539307467f246df
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/72775


Tested-by: core-ci's avatarcore-ci <typo3@b13.com>
Tested-by: Andreas Fernandez's avatarAndreas Fernandez <a.fernandez@scripting-base.de>
Reviewed-by: Andreas Fernandez's avatarAndreas Fernandez <a.fernandez@scripting-base.de>
parent 92072aa1
......@@ -968,14 +968,19 @@ abstract class AbstractItemProvider
$parsedSiteConfiguration = $this->parseSiteConfiguration($result['site'], $fieldConfig['config']['treeConfig']['startingPoints']);
if ($parsedSiteConfiguration !== []) {
// $this->quoteParsedSiteConfiguration() is omitted on purpose, all values are cast to integers
$parsedSiteConfiguration = array_unique(array_map(static function ($value) {
$parsedSiteConfiguration = array_unique(array_map(static function ($value): string {
if (is_array($value)) {
return implode(',', array_map('intval', $value));
}
return (int)$value;
return implode(',', GeneralUtility::intExplode(',', $value, true));
}, $parsedSiteConfiguration));
$fieldConfig['config']['treeConfig']['startingPoints'] = $this->replaceParsedSiteConfiguration($fieldConfig['config']['treeConfig']['startingPoints'], $parsedSiteConfiguration);
$resolvedStartingPoins = $this->replaceParsedSiteConfiguration($fieldConfig['config']['treeConfig']['startingPoints'], $parsedSiteConfiguration);
// Add the resolved starting points while removing empty values
$fieldConfig['config']['treeConfig']['startingPoints'] = implode(
',',
GeneralUtility::trimExplode(',', $resolvedStartingPoins, true)
);
}
return $fieldConfig;
......
......@@ -191,16 +191,31 @@ class TcaCategoryTest extends FunctionalTestCase
'expectedStartingPoints' => '42,4711,12',
'site' => new Site('some-site', 1, ['rootPageId' => 1, 'categories' => ['contentCategory' => 4711]]),
],
'one setting, multiple categories' => [
'one setting, multiple categories as array' => [
'inputStartingPoints' => '###SITE:categories.contentCategories###',
'expectedStartingPoints' => '4711,4712,42',
'site' => new Site('some-site', 1, ['rootPageId' => 1, 'categories' => ['contentCategories' => [4711, 4712, 42]]]),
],
'one setting, multiple categories as csv' => [
'inputStartingPoints' => '###SITE:categories.contentCategories###',
'expectedStartingPoints' => '4711,4712,42',
'site' => new Site('some-site', 1, ['rootPageId' => 1, 'categories' => ['contentCategories' => '4711,4712,42']]),
],
'two settings' => [
'inputStartingPoints' => '42,###SITE:categories.contentCategory###,12,###SITE:foobar###',
'expectedStartingPoints' => '42,4711,12,1',
'site' => new Site('some-site', 1, ['rootPageId' => 1, 'foobar' => 1, 'categories' => ['contentCategory' => 4711]]),
],
'one invalid settings' => [
'inputStartingPoints' => '42,12,###SITE:invalid###',
'expectedStartingPoints' => '42,12',
'site' => new Site('some-site', 1, ['rootPageId' => 1]),
],
'one valid and one invalid setting' => [
'inputStartingPoints' => '42,###SITE:invalid###,12,###SITE:categories.contentCategory###',
'expectedStartingPoints' => '42,12,4711,4712',
'site' => new Site('some-site', 1, ['rootPageId' => 1, 'categories' => ['contentCategory' => '4711,4712']]),
],
];
}
......
Supports Markdown
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