[BUGFIX] Extension Manager doesn't care about configuration sorting
authorNicole Cordes <nicole@cordes.co>
Fri, 16 Nov 2012 23:43:41 +0000 (00:43 +0100)
committerHelmut Hummel <helmut.hummel@typo3.org>
Mon, 26 Nov 2012 22:47:58 +0000 (23:47 +0100)
When showing the configuration of an extension actually the Extension
Manager doesn't care about the given sorting. This is because there is
only a merging of configuration arrays.

After merging we have to take care of the value in 'subcat' key and sort
each subcategorie by those values.

Change-Id: Idb27554be40603c4af7e0506f039d0c0416a0d9a
Fixes: #43041
Releases: 6.0
Reviewed-on: http://review.typo3.org/16502
Reviewed-by: Philipp Gampe
Tested-by: Philipp Gampe
Reviewed-by: Wouter Wolters
Tested-by: Wouter Wolters
Reviewed-by: Stefan Neufeind
Tested-by: Stefan Neufeind
Reviewed-by: Helmut Hummel
Tested-by: Helmut Hummel
typo3/sysext/extensionmanager/Classes/Domain/Repository/ConfigurationItemRepository.php
typo3/sysext/extensionmanager/Tests/Unit/Domain/Repository/ConfigurationItemRepositoryTest.php

index 0332865..ab1547a 100644 (file)
@@ -70,7 +70,8 @@ class ConfigurationItemRepository {
                $configRaw = \TYPO3\CMS\Core\Utility\GeneralUtility::getUrl(PATH_site . $extension['siteRelPath'] . '/ext_conf_template.txt');
                $configurationObjectStorage = NULL;
                if ($configRaw) {
-                       $configurationObjectStorage = $this->convertRawConfigurationToObject($configRaw, $extension);
+                       $configurationArray = $this->convertRawConfigurationToArray($configRaw, $extension);
+                       $configurationObjectStorage = $this->convertHierarchicArrayToObject($configurationArray);
                }
                return $configurationObjectStorage;
        }
@@ -80,9 +81,9 @@ class ConfigurationItemRepository {
         *
         * @param string $configRaw
         * @param array $extension array with extension information
-        * @return \SplObjectStorage
+        * @return array
         */
-       protected function convertRawConfigurationToObject($configRaw, array $extension) {
+       protected function convertRawConfigurationToArray($configRaw, array $extension) {
                $defaultConfiguration = $this->createArrayFromConstants($configRaw, $extension);
                $metaInformation = $this->addMetaInformation($defaultConfiguration);
                $configuration = $this->mergeWithExistingConfiguration($defaultConfiguration, $extension);
@@ -90,8 +91,22 @@ class ConfigurationItemRepository {
                foreach ($configuration as $configurationOption) {
                        $hierarchicConfiguration = \TYPO3\CMS\Core\Utility\GeneralUtility::array_merge_recursive_overrule($this->buildConfigurationArray($configurationOption, $extension), $hierarchicConfiguration);
                }
-               $configurationObjectStorage = $this->convertHierarchicArrayToObject(\TYPO3\CMS\Core\Utility\GeneralUtility::array_merge_recursive_overrule($hierarchicConfiguration, $metaInformation));
-               return $configurationObjectStorage;
+
+               // Flip category array as it was merged the other way around
+               $hierarchicConfiguration = array_reverse($hierarchicConfiguration);
+
+               // Sort configurations of each subcategory
+               foreach ($hierarchicConfiguration as &$catConfigurationArray) {
+                       foreach ($catConfigurationArray as &$subcatConfigurationArray) {
+                               uasort($subcatConfigurationArray, function ($a, $b) {
+                                       return strnatcmp($a['subcat'], $b['subcat']);
+                               });
+                       }
+                       unset($subcatConfigurationArray);
+               }
+               unset($tempConfiguration);
+
+               return \TYPO3\CMS\Core\Utility\GeneralUtility::array_merge_recursive_overrule($hierarchicConfiguration, $metaInformation);
        }
 
        /**
index 57451d1..2376035 100644 (file)
@@ -57,6 +57,13 @@ class ConfigurationItemRepositoryTest extends \TYPO3\CMS\Extbase\Tests\Unit\Base
        }
 
        /**
+        * @return void
+        */
+       public function tearDown() {
+               unset($this->configurationItemRepository);
+       }
+
+       /**
         *
         * @test
         * @return void
@@ -399,6 +406,76 @@ TSConstantEditor.advancedbackend {
                $this->assertEquals($expected, $constantsResult);
        }
 
+       /**
+        * @test
+        */
+       public function convertRawConfigurationToArrayReturnsSortedHierarchicArray() {
+               $configRaw = '# cat=basic/enable/10; type=string; label=Item 1: This is the first configuration item
+item1 = one
+
+# cat=basic/enable/20; type=int+; label=Integer Value: Please insert a positive integer value
+integerValue = 1
+
+# cat=advanced/file/10; type=boolean; label=enableJquery: Insert jQuery plugin
+enableJquery = 1';
+               $extension = array();
+
+               $expectedArray = array(
+                       'basic' => array(
+                               'enable' => array(
+                                       'item1' => array(
+                                               'cat' => 'basic',
+                                               'subcat_name' => 'enable',
+                                               'subcat' => 'a/enable/10z',
+                                               'type' => 'string',
+                                               'label' => 'Item 1: This is the first configuration item',
+                                               'name' =>'item1',
+                                               'value' => 'one',
+                                               'default_value' => 'one',
+                                               'labels' => array(
+                                                       0 => 'Item 1',
+                                                       1 => 'This is the first configuration item'
+                                               )
+                                       ),
+                                       'integerValue' => array(
+                                               'cat' => 'basic',
+                                               'subcat_name' => 'enable',
+                                               'subcat' => 'a/enable/20z',
+                                               'type' => 'int+',
+                                               'label' => 'Integer Value: Please insert a positive integer value',
+                                               'name' =>'integerValue',
+                                               'value' => '1',
+                                               'default_value' => '1',
+                                               'labels' => array(
+                                                       0 => 'Integer Value',
+                                                       1 => 'Please insert a positive integer value'
+                                               )
+                                       )
+                               )
+                       ),
+                       'advanced' => array(
+                               'file' => array(
+                                       'enableJquery' => array(
+                                               'cat' => 'advanced',
+                                               'subcat_name' => 'file',
+                                               'subcat' => 'c/file/10z',
+                                               'type' => 'boolean',
+                                               'label' => 'enableJquery: Insert jQuery plugin',
+                                               'name' =>'enableJquery',
+                                               'value' => '1',
+                                               'default_value' => '1',
+                                               'labels' => array(
+                                                       0 => 'enableJquery',
+                                                       1 => 'Insert jQuery plugin'
+                                               )
+                                       ),
+                               )
+                       )
+               );
+
+               $this->assertSame($expectedArray, $this->configurationItemRepository->_callRef('convertRawConfigurationToArray', $configRaw, $extension));
+       }
+
 }