[BUGFIX] Give extension key to addPlugin() in registerPlugin() 36/31336/2
authorChristian Kuhn <lolli@schwarzbu.ch>
Sat, 5 Jul 2014 11:44:19 +0000 (13:44 +0200)
committerWouter Wolters <typo3@wouterwolters.nl>
Sat, 5 Jul 2014 12:10:09 +0000 (14:10 +0200)
With patch #59770 ExtensionManagementUtility::addPlugin() signature
was extended to get the extensionKey as parameter in order to not
use $GLOBALS['_EXTKEY'] anymore if possible.
The parameter is used to determine correct path to plugin icons if
the icon path is not given otherwise.
The patch changes extbase ExtensionUtility::registerPlugin() to give
the extensionKey to addPlugin, too.
With this patch registerPlugin() can be used in TCA/Overrides.
Some tests are added to verify the icon path calculation since it is
not trivial to follow the code flow with all its options and global
array access.

Change-Id: I2dd709ef7ca304bc8c4fda1e7911f18bfe7ad04c
Resolves: #60109
Related: #59770
Related: #59468
Related: #59414
Releases: 6.3, 6.2
Reviewed-on: https://review.typo3.org/31336
Reviewed-by: Wouter Wolters
Tested-by: Wouter Wolters
typo3/sysext/core/Classes/Utility/ExtensionManagementUtility.php
typo3/sysext/extbase/Classes/Utility/ExtensionUtility.php
typo3/sysext/extbase/Tests/Unit/Utility/ExtensionUtilityTest.php

index 00507f6..39d0fe2 100644 (file)
@@ -1238,7 +1238,7 @@ class ExtensionManagementUtility {
         * Use this function to add a frontend plugin to this list of plugin-types - or more generally use this function to add an entry to any selectorbox/radio-button set in the TCEFORMS
         * FOR USE IN ext_tables.php FILES or files in Configuration/TCA/Overrides/*.php Use the latter to benefit from TCA caching!
         *
-        * @param array $itemArray Item Array
+        * @param array $itemArray Numerical array: [0] => Plugin label, [1] => Underscored extension key, [2] => Path to plugin icon relative to TYPO3_mainDir
         * @param string $type Type (eg. "list_type") - basically a field from "tt_content" table
         * @param string $extensionKey The extension key
         * @throws \RuntimeException
index 60368eb..ed5daa3 100644 (file)
@@ -125,7 +125,21 @@ tt_content.' . $pluginSignature . ' {
                }
                $extensionName = str_replace(' ', '', ucwords(str_replace('_', ' ', $extensionName)));
                $pluginSignature = strtolower($extensionName) . '_' . strtolower($pluginName);
-               \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addPlugin(array($pluginTitle, $pluginSignature, $pluginIconPathAndFilename), $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions'][$extensionName]['plugins'][$pluginName]['pluginType']);
+
+               // At this point $extensionName is normalized, no matter which format the method was feeded with.
+               // Calculate the original extensionKey from this again.
+               $extensionKey = \TYPO3\CMS\Core\Utility\GeneralUtility::camelCaseToLowerCaseUnderscored($extensionName);
+
+               // pluginType is usually defined by configurePlugin() in the global array. Use this or fall back to default "list_type".
+               $pluginType = isset($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions'][$extensionName]['plugins'][$pluginName]['pluginType'])
+                       ? $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions'][$extensionName]['plugins'][$pluginName]['pluginType']
+                       : 'list_type';
+
+               \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addPlugin(
+                       array($pluginTitle, $pluginSignature, $pluginIconPathAndFilename),
+                       $pluginType,
+                       $extensionKey
+               );
        }
 
        /**
index b63ac1d..eb1a860 100644 (file)
@@ -251,4 +251,66 @@ class ExtensionUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                );
                $this->assertEquals($expectedResult, $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions']['MyExtension']['plugins']['Pi1']);
        }
+
+       /**
+        * Tests method combination of registerPlugin() and its dependency addPlugin() to
+        * verify plugin icon path resolving works.
+        *
+        * @test
+        */
+       public function registerPluginTriggersAddPluginWhichSetsPluginIconPathIfUsingUnderscoredExtensionNameAndIconPathNotGiven() {
+               $GLOBALS['TCA']['tt_content']['columns']['list_type']['config']['items'] = array();
+               $GLOBALS['TYPO3_LOADED_EXT'] = array();
+               $GLOBALS['TYPO3_LOADED_EXT']['indexed_search']['ext_icon'] = 'foo.gif';
+               \TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerPlugin(
+                       'indexed_search',
+                       'Pi2',
+                       'Testing'
+               );
+               $this->assertEquals(
+                       'sysext/indexed_search/foo.gif',
+                       $GLOBALS['TCA']['tt_content']['columns']['list_type']['config']['items'][0][2]
+               );
+       }
+
+       /**
+        * Tests method combination of registerPlugin() and its dependency addPlugin() to
+        * verify plugin icon path resolving works.
+        *
+        * @test
+        */
+       public function registerPluginTriggersAddPluginWhichSetsPluginIconPathIfUsingUpperCameCasedExtensionNameAndIconPathNotGiven() {
+               $GLOBALS['TCA']['tt_content']['columns']['list_type']['config']['items'] = array();
+               $GLOBALS['TYPO3_LOADED_EXT'] = array();
+               $GLOBALS['TYPO3_LOADED_EXT']['indexed_search']['ext_icon'] = 'foo.gif';
+               \TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerPlugin(
+                       'IndexedSearch',
+                       'Pi2',
+                       'Testing'
+               );
+               $this->assertEquals(
+                       'sysext/indexed_search/foo.gif',
+                       $GLOBALS['TCA']['tt_content']['columns']['list_type']['config']['items'][0][2]
+               );
+       }
+
+       /**
+        * Tests method combination of registerPlugin() and its dependency addPlugin() to
+        * verify plugin icon path resolving works.
+        *
+        * @test
+        */
+       public function registerPluginTriggersAddPluginWhichSetsPluginIconPathIfIconPathIsGiven() {
+               $GLOBALS['TCA']['tt_content']['columns']['list_type']['config']['items'] = array();
+               \TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerPlugin(
+                       'IndexedSearch',
+                       'Pi2',
+                       'Testing',
+                       'sysext/indexed_search/foo.gif'
+               );
+               $this->assertEquals(
+                       'sysext/indexed_search/foo.gif',
+                       $GLOBALS['TCA']['tt_content']['columns']['list_type']['config']['items'][0][2]
+               );
+       }
 }