[TASK] Simplify icon handling in FormEngine 60/42860/6
authorFrank Nägler <frank.naegler@typo3.org>
Mon, 24 Aug 2015 17:58:29 +0000 (19:58 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Fri, 11 Sep 2015 14:37:42 +0000 (16:37 +0200)
Resolves: #69700
Releases: master
Change-Id: Iebdd1331b091a66379e71d9052e08a556270c742
Reviewed-on: http://review.typo3.org/42860
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
14 files changed:
typo3/sysext/backend/Classes/Form/Utility/FormEngineUtility.php
typo3/sysext/compatibility6/Configuration/TCA/Overrides/tt_content.php
typo3/sysext/core/Classes/Migrations/TcaMigration.php
typo3/sysext/core/Classes/Utility/ExtensionManagementUtility.php
typo3/sysext/core/Tests/Unit/Migrations/TcaMigrationTest.php
typo3/sysext/core/Tests/Unit/Utility/ExtensionManagementUtilityTest.php
typo3/sysext/css_styled_content/Configuration/TCA/Overrides/tt_content.php
typo3/sysext/extbase/Tests/Unit/Utility/ExtensionUtilityTest.php
typo3/sysext/felogin/Configuration/TCA/Overrides/tt_content.php
typo3/sysext/filemetadata/Configuration/TCA/Overrides/sys_file_metadata.php
typo3/sysext/form/Configuration/TCA/Overrides/tt_content.php
typo3/sysext/frontend/Configuration/TCA/tt_content.php
typo3/sysext/mediace/Configuration/TCA/Overrides/tt_content.php
typo3/sysext/sys_note/Configuration/TCA/sys_note.php

index f9f6ff0..6faefac 100644 (file)
@@ -18,6 +18,7 @@ use TYPO3\CMS\Core\Utility\ArrayUtility;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Core\Utility\PathUtility;
 use TYPO3\CMS\Backend\Utility\IconUtility;
+use TYPO3\CMS\Core\Utility\StringUtility;
 use TYPO3\CMS\Lang\LanguageService;
 use TYPO3\CMS\Backend\Utility\BackendUtility;
 use TYPO3\CMS\Core\Database\DatabaseConnection;
@@ -159,35 +160,24 @@ class FormEngineUtility {
         * @internal
         */
        static public function getIcon($icon) {
+               $selIconFile = '';
                $selIconInfo = FALSE;
-               if (substr($icon, 0, 4) == 'EXT:') {
-                       $file = GeneralUtility::getFileAbsFileName($icon);
-                       if ($file) {
-                               $file = PathUtility::stripPathSitePrefix($file);
-                               $selIconFile = '../' . $file;
-                               $selIconInfo = @getimagesize((PATH_site . $file));
-                       } else {
-                               $selIconFile = '';
+               $icon = (string)$icon;
+               if (StringUtility::beginsWith($icon, 'EXT:')) {
+                       $absoluteFilePath = GeneralUtility::getFileAbsFileName($icon);
+                       if (!empty($absoluteFilePath)) {
+                               $selIconFile = '../' . PathUtility::stripPathSitePrefix($absoluteFilePath);
+                               $selIconInfo = (StringUtility::endsWith($absoluteFilePath, '.svg'))
+                                       ? TRUE
+                                       : getimagesize($absoluteFilePath);
                        }
-               } elseif (substr($icon, 0, 3) == '../') {
+               } elseif (StringUtility::beginsWith($icon, '../')) {
+                       // @TODO: this is special modList, files from folders and selicon
                        $selIconFile = GeneralUtility::resolveBackPath($icon);
                        if (is_file(PATH_site . GeneralUtility::resolveBackPath(substr($icon, 3)))) {
-                               if (\TYPO3\CMS\Core\Utility\StringUtility::endsWith($icon, '.svg')) {
-                                       $selIconInfo = TRUE;
-                               } else {
-                                       $selIconInfo = getimagesize((PATH_site . GeneralUtility::resolveBackPath(substr($icon, 3))));
-                               }
-                       }
-               } elseif (substr($icon, 0, 4) == 'ext/' || substr($icon, 0, 7) == 'sysext/') {
-                       $selIconFile = $icon;
-                       if (is_file(PATH_typo3 . $icon)) {
-                               $selIconInfo = getimagesize(PATH_typo3 . $icon);
-                       }
-               } else {
-                       $selIconFile = IconUtility::skinImg('', 'gfx/' . $icon, '', 1);
-                       $iconPath = $selIconFile;
-                       if (is_file(PATH_typo3 . $iconPath)) {
-                               $selIconInfo = getimagesize(PATH_typo3 . $iconPath);
+                               $selIconInfo = (StringUtility::endsWith($icon, '.svg'))
+                                       ? TRUE
+                                       : getimagesize((PATH_site . GeneralUtility::resolveBackPath(substr($icon, 3))));
                        }
                }
                if ($selIconInfo === FALSE) {
index 0f7b8dc..37e3a1e 100644 (file)
@@ -312,7 +312,7 @@ $GLOBALS['TCA']['tt_content']['palettes']['searchform'] = array(
 $additionalCTypeItem = array(
        'LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:CType.I.9',
        'search',
-       'i/tt_content_search.gif'
+       'EXT:t3skin/icons/gfx/i/tt_content_search.gif'
 );
 
 $existingCTypeItems = $GLOBALS['TCA']['tt_content']['columns']['CType']['config']['items'];
@@ -363,7 +363,7 @@ if (!\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('form')) {
        \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTcaSelectItem('tt_content', 'CType', array(
                        'LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:CType.I.8',
                        'mailform',
-                       'i/tt_content_form.gif'
+                       'EXT:t3skin/icons/gfx/i/tt_content_form.gif'
                ),
                'search',
                'before'
index 994bed0..53bf5dc 100644 (file)
@@ -15,6 +15,7 @@ namespace TYPO3\CMS\Core\Migrations;
  */
 
 use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Core\Utility\StringUtility;
 
 /**
  * Migrate TCA from old to new syntax. Used in bootstrap and Flex Form Data Structures.
@@ -44,6 +45,7 @@ class TcaMigration {
                $tca = $this->migrateT3editorWizardWithEnabledByTypeConfigToColumnsOverrides($tca);
                $tca = $this->migrateShowItemAdditionalPaletteToOwnPalette($tca);
                $tca = $this->migrateIconsForFormFieldWizardsToNewLocation($tca);
+               $tca = $this->migrateExtAndSysextPathToEXTPath($tca);
                // @todo: if showitem/defaultExtras wizards[xy] is migrated to columnsOverrides here, enableByTypeConfig could be dropped
                return $tca;
        }
@@ -394,4 +396,49 @@ class TcaMigration {
 
                return $newTca;
        }
+
+       /**
+        * Migrate file reference which starts with ext/ or sysext/ to EXT:
+        *
+        * @param array $tca Incoming TCA
+        * @return array Migrated TCA
+        */
+       protected function migrateExtAndSysextPathToEXTPath($tca) {
+               foreach ($tca as $table => &$tableDefinition) {
+                       if (!isset($tableDefinition['columns']) || !is_array($tableDefinition['columns'])) {
+                               continue;
+                       }
+                       foreach ($tableDefinition['columns'] as $fieldName => &$fieldConfig) {
+                               if (
+                                       !empty($fieldConfig['config']['type']) // type is set
+                                       && trim($fieldConfig['config']['type']) === 'select' // to "select"
+                                       && isset($fieldConfig['config']['items'])
+                                       && is_array($fieldConfig['config']['items']) // and there are items
+                               ) {
+                                       foreach ($fieldConfig['config']['items'] as &$itemConfig) {
+                                               // more then two values? then the third entry is the image path
+                                               if (count($itemConfig) > 2) {
+                                                       // If the path starts with ext/ or sysext/ migrate it
+                                                       if (
+                                                               StringUtility::beginsWith($itemConfig[2], 'ext/')
+                                                               || StringUtility::beginsWith($itemConfig[2], 'sysext/')
+                                                       ) {
+                                                               $tcaPath = implode('.', [$table, 'columns', $fieldName, 'config', 'items']);
+                                                               $pathParts = GeneralUtility::trimExplode('/', $itemConfig[2]);
+                                                               // remove first element (ext or sysext)
+                                                               array_shift($pathParts);
+                                                               $path = implode('/', $pathParts);
+                                                               $this->messages[] = '[' . $tcaPath . '] ext/ or sysext/ within the path (' . $path . ') in items array is deprecated, use EXT: reference';
+                                                               $itemConfig[2] = 'EXT:' . $path;
+                                                       } elseif (StringUtility::beginsWith($itemConfig[2], 'i/')) {
+                                                               $this->messages[] = '[' . $tcaPath . '] i/ within the path (' . $path . ') in items array is deprecated, use EXT: reference';
+                                                               $itemConfig[2] = 'EXT:t3skin/icons/gfx/' . $itemConfig[2];
+                                                       }
+                                               }
+                                       }
+                               }
+                       }
+               }
+               return $tca;
+       }
 }
index ca2dd18..7a2f0b4 100644 (file)
@@ -1288,7 +1288,7 @@ class ExtensionManagementUtility {
                        );
                }
                if ($extensionKey && !$itemArray[2] && isset($GLOBALS['TYPO3_LOADED_EXT'][$extensionKey]['ext_icon'])) {
-                       $itemArray[2] = self::extRelPath($extensionKey) . $GLOBALS['TYPO3_LOADED_EXT'][$extensionKey]['ext_icon'];
+                       $itemArray[2] = 'EXT:' . $extensionKey . '/' . $GLOBALS['TYPO3_LOADED_EXT'][$extensionKey]['ext_icon'];
                }
                if (is_array($GLOBALS['TCA']['tt_content']['columns']) && is_array($GLOBALS['TCA']['tt_content']['columns'][$type]['config']['items'])) {
                        foreach ($GLOBALS['TCA']['tt_content']['columns'][$type]['config']['items'] as $k => $v) {
index 510d6a6..e9dc18a 100644 (file)
@@ -447,4 +447,82 @@ class TcaMigrationTest extends UnitTestCase {
                $subject = new TcaMigration();
                $this->assertEquals($expected, $subject->migrate($input));
        }
+
+       /**
+        * @test
+        */
+       public function migrateExtAndSysextPathToEXTPath() {
+               $input = array(
+                       'aTable' => array(
+                               'columns' => array(
+                                       'foo' => array(
+                                               'config' => array(
+                                                       'type' => 'select',
+                                                       'items' => array(
+                                                               array('foo', 0, 'ext/myext/foo/bar.gif'),
+                                                               array('bar', 1, 'sysext/myext/foo/bar.gif'),
+                                                       ),
+                                               ),
+                                       ),
+                               ),
+                       ),
+               );
+
+               $expected = array(
+                       'aTable' => array(
+                               'columns' => array(
+                                       'foo' => array(
+                                               'config' => array(
+                                                       'type' => 'select',
+                                                       'items' => array(
+                                                               array('foo', 0, 'EXT:myext/foo/bar.gif'),
+                                                               array('bar', 1, 'EXT:myext/foo/bar.gif'),
+                                                       ),
+                                               ),
+                                       ),
+                               ),
+                       ),
+               );
+
+               $subject = new TcaMigration();
+               $this->assertEquals($expected, $subject->migrate($input));
+       }
+
+       /**
+        * @test
+        */
+       public function migratePathWhichStartsWithIToEXTPath() {
+               $input = array(
+                       'aTable' => array(
+                               'columns' => array(
+                                       'foo' => array(
+                                               'config' => array(
+                                                       'type' => 'select',
+                                                       'items' => array(
+                                                               array('foo', 0, 'i/tt_content.gif'),
+                                                       ),
+                                               ),
+                                       ),
+                               ),
+                       ),
+               );
+
+               $expected = array(
+                       'aTable' => array(
+                               'columns' => array(
+                                       'foo' => array(
+                                               'config' => array(
+                                                       'type' => 'select',
+                                                       'items' => array(
+                                                               array('foo', 0, 'EXT:t3skin/icons/gfx/i/tt_content.gif'),
+                                                       ),
+                                               ),
+                                       ),
+                               ),
+                       ),
+               );
+
+               $subject = new TcaMigration();
+               $this->assertEquals($expected, $subject->migrate($input));
+       }
 }
index fcfe2fa..c191559 100644 (file)
@@ -1803,7 +1803,7 @@ class ExtensionManagementUtilityTest extends UnitTestCase {
                        array(
                                'label',
                                $extKey,
-                               'sysext/' . $extKey . '/foo.gif'
+                               'EXT:' . $extKey . '/foo.gif'
                        )
                );
                $GLOBALS['TCA']['tt_content']['columns']['list_type']['config']['items'] = array();
@@ -1823,7 +1823,7 @@ class ExtensionManagementUtilityTest extends UnitTestCase {
                        array(
                                'label',
                                $extKey,
-                               'sysext/' . $extKey . '/foo.gif'
+                               'EXT:' . $extKey . '/foo.gif'
                        )
                );
                $GLOBALS['TCA']['tt_content']['columns']['list_type']['config']['items'] = array();
index 573d399..0b823f2 100644 (file)
@@ -373,17 +373,17 @@ array_splice(
                array(
                        'LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:CType.I.1',
                        'text',
-                       'i/tt_content.gif'
+                       'EXT:t3skin/icons/gfx/i/tt_content.gif'
                ),
                array(
                        'LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:CType.I.2',
                        'textpic',
-                       'i/tt_content_textpic.gif'
+                       'EXT:t3skin/icons/gfx/i/tt_content_textpic.gif'
                ),
                array(
                        'LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:CType.I.3',
                        'image',
-                       'i/tt_content_image.gif'
+                       'EXT:t3skin/icons/gfx/i/tt_content_image.gif'
                )
        )
 );
index 6e97e45..4150f1c 100644 (file)
@@ -269,7 +269,7 @@ class ExtensionUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                        'Testing'
                );
                $this->assertEquals(
-                       'sysext/indexed_search/foo.gif',
+                       'EXT:indexed_search/foo.gif',
                        $GLOBALS['TCA']['tt_content']['columns']['list_type']['config']['items'][0][2]
                );
        }
@@ -290,7 +290,7 @@ class ExtensionUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                        'Testing'
                );
                $this->assertEquals(
-                       'sysext/indexed_search/foo.gif',
+                       'EXT:indexed_search/foo.gif',
                        $GLOBALS['TCA']['tt_content']['columns']['list_type']['config']['items'][0][2]
                );
        }
@@ -307,10 +307,10 @@ class ExtensionUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                        'IndexedSearch',
                        'Pi2',
                        'Testing',
-                       'sysext/indexed_search/foo.gif'
+                       'EXT:indexed_search/foo.gif'
                );
                $this->assertEquals(
-                       'sysext/indexed_search/foo.gif',
+                       'EXT:indexed_search/foo.gif',
                        $GLOBALS['TCA']['tt_content']['columns']['list_type']['config']['items'][0][2]
                );
        }
index 8c22e44..6a621a5 100644 (file)
@@ -13,7 +13,7 @@ defined('TYPO3_MODE') or die();
 $additionalCTypeItem = array(
        'LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:CType.I.10',
        'login',
-       'i/tt_content_login.gif'
+       'EXT:t3skin/icons/gfx/i/tt_content_login.gif'
 );
 
 $existingCTypeItems = $GLOBALS['TCA']['tt_content']['columns']['CType']['config']['items'];
index 5fac7d7..8b2be94 100644 (file)
@@ -115,17 +115,17 @@ $tca = array(
                                        array(
                                                'LLL:EXT:filemetadata/Resources/Private/Language/locallang_tca.xlf:sys_file_metadata.status.1',
                                                1,
-                                               \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath('filemetadata') . 'Resources/Public/Icons/status_1.png'
+                                               'EXT:filemetadata/Resources/Public/Icons/status_1.png'
                                        ),
                                        array(
                                                'LLL:EXT:filemetadata/Resources/Private/Language/locallang_tca.xlf:sys_file_metadata.status.2',
                                                2,
-                                               \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath('filemetadata') . 'Resources/Public/Icons/status_2.png'
+                                               'EXT:filemetadata/Resources/Public/Icons/status_2.png'
                                        ),
                                        array(
                                                'LLL:EXT:filemetadata/Resources/Private/Language/locallang_tca.xlf:sys_file_metadata.status.3',
                                                3,
-                                               \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath('filemetadata') . 'Resources/Public/Icons/status_3.png'
+                                               'EXT:filemetadata/Resources/Public/Icons/status_3.png'
                                        ),
                                ),
                        ),
index 7e3e8d9..3ca2b64 100644 (file)
@@ -9,7 +9,7 @@ $GLOBALS['TCA']['tt_content']['ctrl']['typeicon_classes']['mailform'] = 'mimetyp
 $additionalCTypeItem = array(
        'LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:CType.I.8',
        'mailform',
-       'i/tt_content_form.gif'
+       'EXT:t3skin/icons/gfx/i/tt_content_form.gif'
 );
 
 $existingCTypeItems = $GLOBALS['TCA']['tt_content']['columns']['CType']['config']['items'];
index da17791..8b57044 100644 (file)
@@ -65,7 +65,7 @@ return array(
                                        array(
                                                'LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:CType.I.0',
                                                'header',
-                                               'i/tt_content_header.gif'
+                                               'EXT:t3skin/icons/gfx/i/tt_content_header.gif'
                                        ),
                                        array(
                                                'LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:CType.div.lists',
@@ -74,17 +74,17 @@ return array(
                                        array(
                                                'LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:CType.I.4',
                                                'bullets',
-                                               'i/tt_content_bullets.gif'
+                                               'EXT:t3skin/icons/gfx/i/tt_content_bullets.gif'
                                        ),
                                        array(
                                                'LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:CType.I.5',
                                                'table',
-                                               'i/tt_content_table.gif'
+                                               'EXT:t3skin/icons/gfx/i/tt_content_table.gif'
                                        ),
                                        array(
                                                'LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:CType.I.6',
                                                'uploads',
-                                               'i/tt_content_uploads.gif'
+                                               'EXT:t3skin/icons/gfx/i/tt_content_uploads.gif'
                                        ),
                                        array(
                                                'LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:CType.div.special',
@@ -93,27 +93,27 @@ return array(
                                        array(
                                                'LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:CType.I.12',
                                                'menu',
-                                               'i/tt_content_menu.gif'
+                                               'EXT:t3skin/icons/gfx/i/tt_content_menu.gif'
                                        ),
                                        array(
                                                'LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:CType.I.13',
                                                'shortcut',
-                                               'i/tt_content_shortcut.gif'
+                                               'EXT:t3skin/icons/gfx/i/tt_content_shortcut.gif'
                                        ),
                                        array(
                                                'LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:CType.I.14',
                                                'list',
-                                               'i/tt_content_list.gif'
+                                               'EXT:t3skin/icons/gfx/i/tt_content_list.gif'
                                        ),
                                        array(
                                                'LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:CType.I.16',
                                                'div',
-                                               'i/tt_content_div.gif'
+                                               'EXT:t3skin/icons/gfx/i/tt_content_div.gif'
                                        ),
                                        array(
                                                'LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:CType.I.17',
                                                'html',
-                                               'i/tt_content_html.gif'
+                                               'EXT:t3skin/icons/gfx/i/tt_content_html.gif'
                                        )
                                ),
                                'default' => 'text',
index 9a31ab3..40fe7a8 100644 (file)
@@ -13,7 +13,7 @@ $GLOBALS['TCA']['tt_content']['ctrl']['typeicon_classes']['media'] = 'mimetypes-
        array(
                'LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:CType.I.7',
                'multimedia',
-               'i/tt_content_mm.gif'
+               'EXT:t3skin/icons/gfx/i/tt_content_mm.gif'
        ),
        'menu', 'before'
 );
@@ -21,7 +21,7 @@ $GLOBALS['TCA']['tt_content']['ctrl']['typeicon_classes']['media'] = 'mimetypes-
        array(
                'LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:CType.I.18',
                'media',
-               'i/tt_content_mm.gif'
+               'EXT:t3skin/icons/gfx/i/tt_content_mm.gif'
        ),
        'menu', 'before'
 );
index c9e5077..85fbf58 100644 (file)
@@ -22,10 +22,10 @@ return array(
                                'type' => 'select',
                                'items' => array(
                                        array('', '0'),
-                                       array('LLL:EXT:sys_note/Resources/Private/Language/locallang_tca.xlf:sys_note.category.I.1', '1', 'sysext/sys_note/Resources/Public/Icons/instruction.png'),
-                                       array('LLL:EXT:sys_note/Resources/Private/Language/locallang_tca.xlf:sys_note.category.I.3', '3', 'sysext/sys_note/Resources/Public/Icons/note.png'),
-                                       array('LLL:EXT:sys_note/Resources/Private/Language/locallang_tca.xlf:sys_note.category.I.4', '4', 'sysext/sys_note/Resources/Public/Icons/todo.png'),
-                                       array('LLL:EXT:sys_note/Resources/Private/Language/locallang_tca.xlf:sys_note.category.I.2', '2', 'sysext/sys_note/Resources/Public/Icons/template.png')
+                                       array('LLL:EXT:sys_note/Resources/Private/Language/locallang_tca.xlf:sys_note.category.I.1', '1', 'EXT:sys_note/Resources/Public/Icons/instruction.png'),
+                                       array('LLL:EXT:sys_note/Resources/Private/Language/locallang_tca.xlf:sys_note.category.I.3', '3', 'EXT:sys_note/Resources/Public/Icons/note.png'),
+                                       array('LLL:EXT:sys_note/Resources/Private/Language/locallang_tca.xlf:sys_note.category.I.4', '4', 'EXT:sys_note/Resources/Public/Icons/todo.png'),
+                                       array('LLL:EXT:sys_note/Resources/Private/Language/locallang_tca.xlf:sys_note.category.I.2', '2', 'EXT:sys_note/Resources/Public/Icons/template.png')
                                ),
                                'default' => '0'
                        )