From 04e8456a65f684c304363045a8157cd949e5821d Mon Sep 17 00:00:00 2001 From: Jigal van Hemert Date: Wed, 31 Oct 2012 22:45:33 +0100 Subject: [PATCH] [BUGFIX] EM 6.0 parse configuration type 'options' correctly The labels for the options are in the options= part, not in the label= part. Parsing the options correctly renders the select box as intended. Change-Id: I5a3c9e888f248a91c1c79f7a69f82a6a87880a3e Fixes: #42252 Releases: 6.0 Reviewed-on: http://review.typo3.org/16090 Reviewed-by: Dmitry Dulepov Tested-by: Dmitry Dulepov --- .../ConfigurationItemRepository.php | 16 ++++++---- .../ConfigurationItemRepositoryTest.php | 30 +++++++++++++++++++ 2 files changed, 40 insertions(+), 6 deletions(-) diff --git a/typo3/sysext/extensionmanager/Classes/Domain/Repository/ConfigurationItemRepository.php b/typo3/sysext/extensionmanager/Classes/Domain/Repository/ConfigurationItemRepository.php index e1e28349f851..67fbd19dec11 100644 --- a/typo3/sysext/extensionmanager/Classes/Domain/Repository/ConfigurationItemRepository.php +++ b/typo3/sysext/extensionmanager/Classes/Domain/Repository/ConfigurationItemRepository.php @@ -127,13 +127,17 @@ class ConfigurationItemRepository { * @return array */ protected function extractInformationForConfigFieldsOfTypeOptions(array $configurationOption) { - preg_match('/options\\[(.*)\\]/is', $configurationOption['type'], $typeMatches); - preg_match('/options\\[(.*)\\]/is', $configurationOption['label'], $labelMatches); - $optionValues = explode(',', $typeMatches[1]); - $optionLabels = explode(',', $labelMatches[1]); - $configurationOption['generic'] = $labelMatches ? array_combine($optionLabels, $optionValues) : array_combine($optionValues, $optionValues); + preg_match('/options\[(.*)\]/is', $configurationOption['type'], $typeMatches); + $optionItems = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $typeMatches[1]); + foreach ($optionItems as $optionItem) { + $optionPair = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode('=', $optionItem); + if (count($optionPair) === 2) { + $configurationOption['generic'][$optionPair[0]] = $optionPair[1]; + } else { + $configurationOption['generic'][$optionPair[0]] = $optionPair[0]; + } + } $configurationOption['type'] = 'options'; - $configurationOption['label'] = str_replace($labelMatches[0], '', $configurationOption['label']); return $configurationOption; } diff --git a/typo3/sysext/extensionmanager/Tests/Unit/Domain/Repository/ConfigurationItemRepositoryTest.php b/typo3/sysext/extensionmanager/Tests/Unit/Domain/Repository/ConfigurationItemRepositoryTest.php index e7bb3e1407a7..6aaff0ce7e32 100644 --- a/typo3/sysext/extensionmanager/Tests/Unit/Domain/Repository/ConfigurationItemRepositoryTest.php +++ b/typo3/sysext/extensionmanager/Tests/Unit/Domain/Repository/ConfigurationItemRepositoryTest.php @@ -176,6 +176,36 @@ class ConfigurationItemRepositoryTest extends \TYPO3\CMS\Extbase\Tests\Unit\Base $this->assertEquals($option['typeComparisonValue'], $optionModified['type']); } + /** + * + * @test + * @return void + */ + public function extractInformationForConfigFieldsOfTypeOptionsWithLabelsAndValuesAddsGenericTypeAndLabelInformation() { + $option = array( + 'cat' => 'basic', + 'subcat_name' => 'enable', + 'subcat' => 'a/enable/100z', + 'type' => 'options[Minimal (Most features disabled. Administrator needs to enable them using TypoScript. For advanced administrators only.)=MINIMAL,Typical (Most commonly used features are enabled. Select this option if you are unsure which one to use.) = TYPICAL,Demo (Show-off configuration. Includes pre-configured styles. Not for production environments.)=DEMO]', + 'label' => 'Default configuration settings', + 'name' => 'defaultConfiguration', + 'value' => 'Typical (Most commonly used features are enabled. Select this option if you are unsure which one to use.)', + 'default_value' => 'Typical (Most commonly used features are enabled. Select this option if you are unsure which one to use.)', + 'genericComparisonValue' => array( + 'Minimal (Most features disabled. Administrator needs to enable them using TypoScript. For advanced administrators only.)' => 'MINIMAL', + 'Typical (Most commonly used features are enabled. Select this option if you are unsure which one to use.)' => 'TYPICAL', + 'Demo (Show-off configuration. Includes pre-configured styles. Not for production environments.)' => 'DEMO' + ), + 'typeComparisonValue' => 'options' + ); + $optionModified = $this->configurationItemRepository->_callRef('extractInformationForConfigFieldsOfTypeOptions', $option); + $this->assertArrayHasKey('generic', $optionModified); + $this->assertArrayHasKey('type', $optionModified); + $this->assertArrayHasKey('label', $optionModified); + $this->assertEquals($option['genericComparisonValue'], $optionModified['generic']); + $this->assertEquals($option['typeComparisonValue'], $optionModified['type']); + } + /** * * @test -- 2.20.1