[!!!][FEATURE] Add showIconTable option for selectSingle fields 33/43933/10
authorNicole Cordes <typo3@cordes.co>
Fri, 9 Oct 2015 11:18:33 +0000 (13:18 +0200)
committerGeorg Ringer <georg.ringer@gmail.com>
Thu, 15 Oct 2015 11:45:19 +0000 (13:45 +0200)
This patch introduces a new option "showIconTable" for select fields
with renderType "selectSingle". Furthermore it removes the functionality
for old options "noIconsBelowSelect" "foreign_table_loadIcons" and
"suppress_icons".

The advantages is to have only one option which controls the visibility
of the icon table instead of having multiple ways.

A migration wizards sets the new property according to the old behavior
and generates deprecation messages for the tables and fields using old
options.

Core TCA definitions are adjusted to use the new option. The language
fields are changed to show the icon table by default.

Resolves: #70033
Releases: master
Change-Id: I611cd50233255bbe35a371efac1f59dc086aa73e
Reviewed-on: http://review.typo3.org/43933
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
17 files changed:
typo3/sysext/backend/Classes/Form/Element/SelectSingleElement.php
typo3/sysext/core/Classes/Migrations/TcaMigration.php
typo3/sysext/core/Configuration/TCA/pages.php
typo3/sysext/core/Configuration/TCA/sys_category.php
typo3/sysext/core/Configuration/TCA/sys_collection.php
typo3/sysext/core/Configuration/TCA/sys_file_collection.php
typo3/sysext/core/Configuration/TCA/sys_file_metadata.php
typo3/sysext/core/Configuration/TCA/sys_file_reference.php
typo3/sysext/core/Configuration/TCA/sys_language.php
typo3/sysext/core/Documentation/Changelog/master/Breaking-70033-TcaIconOptionsForSelectFields.rst [new file with mode: 0644]
typo3/sysext/core/Documentation/Changelog/master/Feature-70033-IntroducedTcaOptionShowIconTableForSelectSingleFields.rst [new file with mode: 0644]
typo3/sysext/core/Tests/Unit/Migrations/TcaMigrationTest.php
typo3/sysext/filemetadata/Configuration/TCA/Overrides/sys_file_metadata.php
typo3/sysext/frontend/Configuration/TCA/pages_language_overlay.php
typo3/sysext/frontend/Configuration/TCA/tt_content.php
typo3/sysext/rtehtmlarea/Configuration/TCA/tx_rtehtmlarea_acronym.php
typo3/sysext/sys_note/Configuration/TCA/sys_note.php

index 65a267c..c394d4f 100644 (file)
@@ -78,7 +78,6 @@ class SelectSingleElement extends AbstractFormElement
         $selectedIndex = 0;
         $selectedIcon = '';
         $selectedValueFound = false;
-        $onlySelectedIconShown = false;
         $size = (int)$config['size'];
 
         // Style set on <select/>
@@ -86,19 +85,6 @@ class SelectSingleElement extends AbstractFormElement
         $disabled = false;
         if (!empty($config['readOnly'])) {
             $disabled = true;
-            $onlySelectedIconShown = true;
-        }
-
-        // Icon configuration:
-        if ($config['suppress_icons'] === 'IF_VALUE_FALSE') {
-            $suppressIcons = empty($parameterArray['itemFormElValue']);
-        } elseif ($config['suppress_icons'] === 'ONLY_SELECTED') {
-            $suppressIcons = false;
-            $onlySelectedIconShown = true;
-        } elseif ($config['suppress_icons']) {
-            $suppressIcons = true;
-        } else {
-            $suppressIcons = false;
         }
 
         // Prepare groups
@@ -143,7 +129,7 @@ class SelectSingleElement extends AbstractFormElement
                 );
 
                 // ICON
-                if ($icon && !$suppressIcons && (!$onlySelectedIconShown || $selected)) {
+                if ($icon) {
                     $selectIcons[] = array(
                         'title' => $title,
                         'icon' => $icon,
@@ -213,7 +199,7 @@ class SelectSingleElement extends AbstractFormElement
         $html[] = '</div>';
 
         // Create icon table:
-        if (!empty($selectIcons) && !$config['noIconsBelowSelect']) {
+        if (!empty($selectIcons) && !empty($config['showIconTable'])) {
             $selectIconColumns = (int)$config['selicon_cols'];
 
             if (!$selectIconColumns) {
@@ -238,9 +224,9 @@ class SelectSingleElement extends AbstractFormElement
                 $html[] =            '<td>';
 
                 if (is_array($selectIcon)) {
-                    $html[] = (!$onlySelectedIconShown ? '<a href="#" title="' . $selectIcon['title'] . '" data-select-index="' . $selectIcon['index'] . '">' : '');
+                    $html[] = '<a href="#" title="' . $selectIcon['title'] . '" data-select-index="' . $selectIcon['index'] . '">';
                     $html[] = $selectIcon['icon'];
-                    $html[] = (!$onlySelectedIconShown ? '</a>' : '');
+                    $html[] = '</a>';
                 }
 
                 $html[] =            '</td>';
index a7c0ae2..ad1372c 100644 (file)
@@ -50,6 +50,7 @@ class TcaMigration
         $tca = $this->migrateIconsInOptionTags($tca);
         $tca = $this->migrateIconfileRelativePathOrFilenameOnlyToExtReference($tca);
         $tca = $this->migrateSelectFieldRenderType($tca);
+        $tca = $this->migrateSelectFieldIconTable($tca);
         $tca = $this->migrateElementBrowserWizardToLinkHandler($tca);
         // @todo: if showitem/defaultExtras wizards[xy] is migrated to columnsOverrides here, enableByTypeConfig could be dropped
         return $tca;
@@ -569,6 +570,51 @@ class TcaMigration
     }
 
     /**
+     * Migrate the visibility of the icon table for fields with "renderType=selectSingle"
+     *
+     * @param array $tca
+     * @return array Migrated TCA
+     */
+    public function migrateSelectFieldIconTable(array $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']['renderType']) || $fieldConfig['config']['renderType'] !== 'selectSingle') {
+                    continue;
+                }
+                if (!empty($fieldConfig['config']['selicon_cols'])) {
+                    $this->messages[] = 'The "showIconTable" setting is missing for table "' . $table . '" and field "' . $fieldName . '"';
+                    // selicon_cols without showIconTable true does not make sense, so set it to true here if not already defined
+                    if (!array_key_exists('showIconTable', $fieldConfig['config'])) {
+                        $fieldConfig['config']['showIconTable'] = true;
+                    }
+                }
+                if (array_key_exists('noIconsBelowSelect', $fieldConfig['config'])) {
+                    $this->messages[] = 'The "noIconsBelowSelect" setting for select fields was removed. Please define the setting "showIconTable" for table "' . $table . '" and field "' . $fieldName . '"';
+                    if (!$fieldConfig['config']['noIconsBelowSelect']) {
+                        // If old setting was explicitly false, enable icon table if not defined yet
+                        if (!array_key_exists('showIconTable', $fieldConfig['config'])) {
+                            $fieldConfig['config']['showIconTable'] = true;
+                        }
+                    }
+                    unset($fieldConfig['config']['noIconsBelowSelect']);
+                }
+                if (array_key_exists('suppress_icons', $fieldConfig['config'])) {
+                    $this->messages[] = 'The "suppress_icons" setting for select fields was removed. Please define the setting "showIconTable" for table "' . $table . '" and field "' . $fieldName . '"';
+                    unset($fieldConfig['config']['suppress_icons']);
+                }
+                if (array_key_exists('foreign_table_loadIcons', $fieldConfig['config'])) {
+                    $this->messages[] = 'The "foreign_table_loadIcons" setting for select fields was removed. Please define the setting "showIconTable" for table "' . $table . '" and field "' . $fieldName . '"';
+                    unset($fieldConfig['config']['foreign_table_loadIcons']);
+                }
+            }
+        }
+        return $tca;
+    }
+
+    /**
      * Migrate wizard "wizard_element_browser" used in mode "wizard" to use the "wizard_link_browser" instead
      *
      * @param array $tca
index 3c8b32b..edbc25b 100644 (file)
@@ -125,7 +125,6 @@ return array(
                     )
                 ),
                 'default' => (string)\TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_DEFAULT,
-                'noIconsBelowSelect' => 1
             )
         ),
         'title' => array(
@@ -731,7 +730,6 @@ return array(
                     )
                 ),
                 'default' => '',
-                'noIconsBelowSelect' => 1
             )
         ),
         'fe_login_mode' => array(
@@ -788,6 +786,7 @@ return array(
                     array('LLL:EXT:frontend/Resources/Private/Language/locallang_tca.xlf:pages.backend_layout.none', -1)
                 ),
                 'itemsProcFunc' => \TYPO3\CMS\Backend\View\BackendLayoutView::class . '->addBackendLayoutItems',
+                'showIconTable' => true,
                 'selicon_cols' => 5,
                 'size' => 1,
                 'maxitems' => 1,
@@ -804,6 +803,7 @@ return array(
                     array('LLL:EXT:frontend/Resources/Private/Language/locallang_tca.xlf:pages.backend_layout.none', -1)
                 ),
                 'itemsProcFunc' => \TYPO3\CMS\Backend\View\BackendLayoutView::class . '->addBackendLayoutItems',
+                'showIconTable' => true,
                 'selicon_cols' => 5,
                 'size' => 1,
                 'maxitems' => 1,
index 830f33c..613784b 100644 (file)
@@ -63,7 +63,8 @@ return array(
                     array('LLL:EXT:lang/locallang_general.xlf:LGL.allLanguages', -1),
                     array('LLL:EXT:lang/locallang_general.xlf:LGL.default_value', 0)
                 ),
-                'default' => 0
+                'default' => 0,
+                'showIconTable' => true,
             )
         ),
         'l10n_parent' => array(
index 2819c82..8b76c1d 100644 (file)
@@ -53,7 +53,8 @@ return array(
                     array('LLL:EXT:lang/locallang_general.xlf:LGL.allLanguages', -1),
                     array('LLL:EXT:lang/locallang_general.xlf:LGL.default_value', 0)
                 ),
-                'default' => 0
+                'default' => 0,
+                'showIconTable' => true,
             )
         ),
         'l10n_parent' => array(
index b24efc0..3ba040c 100644 (file)
@@ -52,7 +52,8 @@ return array(
                     array('LLL:EXT:lang/locallang_general.xlf:LGL.allLanguages', -1),
                     array('LLL:EXT:lang/locallang_general.xlf:LGL.default_value', 0)
                 ),
-                'default' => 0
+                'default' => 0,
+                'showIconTable' => true,
             )
         ),
         'l10n_parent' => array(
index 5dd79b9..b825cb9 100644 (file)
@@ -40,7 +40,8 @@ return array(
                     array('LLL:EXT:lang/locallang_general.xlf:LGL.allLanguages', -1),
                     array('LLL:EXT:lang/locallang_general.xlf:LGL.default_value', 0)
                 ),
-                'default' => 0
+                'default' => 0,
+                'showIconTable' => true,
             )
         ),
         'l10n_parent' => array(
index 36311b2..f3a06e0 100644 (file)
@@ -61,7 +61,8 @@ return array(
                     array('LLL:EXT:lang/locallang_general.xlf:LGL.allLanguages', -1),
                     array('LLL:EXT:lang/locallang_general.xlf:LGL.default_value', 0)
                 ),
-                'default' => 0
+                'default' => 0,
+                'showIconTable' => true,
             )
         ),
         'l10n_parent' => array(
index 11aae8b..69fa06c 100644 (file)
@@ -329,7 +329,8 @@ return array(
                 'selicon_cols' => 16,
                 'size' => 1,
                 'minitems' => 0,
-                'maxitems' => 1
+                'maxitems' => 1,
+                'showIconTable' => true,
             )
         )
     ),
diff --git a/typo3/sysext/core/Documentation/Changelog/master/Breaking-70033-TcaIconOptionsForSelectFields.rst b/typo3/sysext/core/Documentation/Changelog/master/Breaking-70033-TcaIconOptionsForSelectFields.rst
new file mode 100644 (file)
index 0000000..afedb6e
--- /dev/null
@@ -0,0 +1,28 @@
+=====================================================
+Breaking: #70033 - TCA icon options have been removed
+=====================================================
+
+Description
+===========
+
+The ``TCA`` configurations ``noIconsBelowSelect``, ``foreign_table_loadIcons`` and ``suppress_icons`` for select fields with
+the render type ``selectSingle`` have been removed.
+
+
+Impact
+======
+
+The old TCA settings ``noIconsBelowSelect``, ``foreign_table_loadIcons`` and ``suppress_icons`` are ignored and
+deprecation messages are added. A migration handles the update of the settings.
+
+
+Affected Installations
+======================
+
+All installations with extensions that configure the icon table visibility of TCA select fields with one of the old settings.
+
+
+Migration
+=========
+
+Extension authors need to use the new option ``showIconTable`` to define the visibility of the icon table for their select fields.
diff --git a/typo3/sysext/core/Documentation/Changelog/master/Feature-70033-IntroducedTcaOptionShowIconTableForSelectSingleFields.rst b/typo3/sysext/core/Documentation/Changelog/master/Feature-70033-IntroducedTcaOptionShowIconTableForSelectSingleFields.rst
new file mode 100644 (file)
index 0000000..536bfa2
--- /dev/null
@@ -0,0 +1,18 @@
+=============================================================================
+Feature: #70033 - Introduced TCA option showIconTable for selectSingle fields
+=============================================================================
+
+Description
+===========
+
+A new option ``showIconTable`` has been introduced for select fields with render type ``selectSingle`` to enforce or prevent the
+icon table underneath the field. By default the icon table is not shown.
+
+Example
+-------
+
+.. code-block:: php
+
+       // Enforce icon table showing flags
+       $GLOBALS['TCA']['tt_content']['columns']['sys_language_uid']['config']['showIconTable'] = true;
+
index 8dd70db..3698654 100644 (file)
@@ -831,6 +831,153 @@ class TcaMigrationTest extends UnitTestCase
     }
 
     /**
+     * @return array
+     */
+    public function migrateSetsShowIconTableIfMissingDataProvider() {
+        return [
+            'not-a-select-is-kept' => [
+                [
+                    // Given config section
+                    'type' => 'input',
+                ],
+                [
+                    // Expected config section
+                    'type' => 'input',
+                ],
+            ],
+            'not-a-selectSingle-is-kept' => [
+                [
+                    'type' => 'select',
+                    'renderType' => 'selectCheckBox',
+                ],
+                [
+                    'type' => 'select',
+                    'renderType' => 'selectCheckBox',
+                ],
+            ],
+            'noIconsBelowSelect-true-is-removed' => [
+                [
+                    'type' => 'select',
+                    'renderType' => 'selectSingle',
+                    'noIconsBelowSelect' => true,
+                ],
+                [
+                    'type' => 'select',
+                    'renderType' => 'selectSingle',
+                ],
+            ],
+            'noIconsBelowSelect-false-is-removed-sets-showIconTable' => [
+                [
+                    'type' => 'select',
+                    'renderType' => 'selectSingle',
+                    'noIconsBelowSelect' => false,
+                ],
+                [
+                    'type' => 'select',
+                    'renderType' => 'selectSingle',
+                    'showIconTable' => true,
+                ],
+            ],
+            'noIconsBelowSelect-false-is-removed-keeps-given-showIconTable' => [
+                [
+                    'type' => 'select',
+                    'renderType' => 'selectSingle',
+                    'noIconsBelowSelect' => false,
+                    'showIconTable' => false,
+                ],
+                [
+                    'type' => 'select',
+                    'renderType' => 'selectSingle',
+                    'showIconTable' => false,
+                ],
+            ],
+            'suppress-icons-1-is-removed' => [
+                [
+                    'type' => 'select',
+                    'renderType' => 'selectSingle',
+                    'suppress_icons' => '1',
+                ],
+                [
+                    'type' => 'select',
+                    'renderType' => 'selectSingle',
+                ],
+            ],
+            'suppress-icons-value-is-removed' => [
+                [
+                    'type' => 'select',
+                    'renderType' => 'selectSingle',
+                    'suppress_icons' => 'IF_VALUE_FALSE',
+                ],
+                [
+                    'type' => 'select',
+                    'renderType' => 'selectSingle',
+                ],
+            ],
+            'selicon-cols-sets-showIconTable' => [
+                [
+                    'type' => 'select',
+                    'renderType' => 'selectSingle',
+                    'selicon_cols' => 16,
+                ],
+                [
+                    'type' => 'select',
+                    'renderType' => 'selectSingle',
+                    'selicon_cols' => 16,
+                    'showIconTable' => true,
+                ],
+            ],
+            'selicon-cols-does-not-override-given-showIconTable' => [
+                [
+                    'type' => 'select',
+                    'renderType' => 'selectSingle',
+                    'selicon_cols' => 16,
+                    'showIconTable' => false,
+                ],
+                [
+                    'type' => 'select',
+                    'renderType' => 'selectSingle',
+                    'selicon_cols' => 16,
+                    'showIconTable' => false,
+                ],
+            ],
+            'foreign_table_loadIcons-is-removed' => [
+                [
+                    'type' => 'select',
+                    'renderType' => 'selectSingle',
+                    'foreign_table_loadIcons' => true,
+                ],
+                [
+                    'type' => 'select',
+                    'renderType' => 'selectSingle',
+                ],
+            ],
+        ];
+    }
+
+    /**
+     * @test
+     * @dataProvider migrateSetsShowIconTableIfMissingDataProvider
+     * @param array $givenConfig
+     * @param array $expectedConfig
+     */
+    public function migrateSetsShowIconTableIfMissing(array $givenConfig, array $expectedConfig) {
+        $input = [
+            'aTable' => [
+                'columns' => [
+                    'aField' => [
+                        'config' => $givenConfig,
+                    ]
+                ],
+            ],
+        ];
+        $expected = $input;
+        $expected['aTable']['columns']['aField']['config'] = $expectedConfig;
+
+        $subject = new TcaMigration();
+        $this->assertEquals($expected, $subject->migrate($input));
+    }
+
+    /**
      * @test
      */
     public function migrateFixesReferenceToLinkHandler()
index 1fb2c47..9467f57 100644 (file)
@@ -129,6 +129,7 @@ $tca = array(
                         'EXT:filemetadata/Resources/Public/Icons/status_3.png'
                     ),
                 ),
+                'showIconTable' => true,
             ),
         ),
         'keywords' => array(
index f514817..00c734a 100644 (file)
@@ -209,7 +209,8 @@ return array(
                 'foreign_table' => 'sys_language',
                 'foreign_table_where' => 'ORDER BY sys_language.title',
                 'items' => array(), // no default language here, as the pages table is always the default language
-                'default' => 0
+                'default' => 0,
+                'showIconTable' => true,
             )
         ),
         'tx_impexp_origuid' => array('config' => array('type' => 'passthrough')),
index a6f5a2c..ac77f67 100644 (file)
@@ -120,7 +120,6 @@ return array(
                 'default' => 'header',
                 'authMode' => $GLOBALS['TYPO3_CONF_VARS']['BE']['explicitADmode'],
                 'authMode_enforce' => 'strict',
-                'noIconsBelowSelect' => 1
             )
         ),
         'editlock' => array(
@@ -219,7 +218,8 @@ return array(
                         0
                     )
                 ),
-                'default' => 0
+                'default' => 0,
+                'showIconTable' => true,
             )
         ),
         'l18n_parent' => array(
@@ -571,6 +571,7 @@ return array(
                 ),
                 'selicon_cols' => 6,
                 'default' => 0,
+                'showIconTable' => true,
             )
         ),
         'imageborder' => array(
@@ -811,7 +812,6 @@ return array(
                 'itemsProcFunc' => \TYPO3\CMS\Frontend\Hooks\TableColumnHooks::class . '->sortPluginList',
                 'default' => '',
                 'authMode' => $GLOBALS['TYPO3_CONF_VARS']['BE']['explicitADmode'],
-                'noIconsBelowSelect' => 1
             )
         ),
         'select_key' => array(
@@ -1038,7 +1038,6 @@ return array(
                 'size' => 1,
                 'minitems' => 0,
                 'maxitems' => 1,
-                'suppress_icons' => 1,
                 'itemsProcFunc' => \TYPO3\CMS\Core\Category\CategoryRegistry::class . '->getCategoryFieldsForTable',
             )
         ),
index 8274fc2..394b397 100644 (file)
@@ -67,7 +67,8 @@ return array(
                     array('LLL:EXT:lang/locallang_general.xlf:LGL.allLanguages', '-1'),
                     array('LLL:EXT:lang/locallang_general.xlf:LGL.default_value', '0')
                 ),
-                'default' => 0
+                'default' => 0,
+                'showIconTable' => true,
             )
         ),
         'type' => array(
@@ -113,7 +114,6 @@ return array(
                 'foreign_table' => 'static_languages',
                 'foreign_table_where' => 'ORDER BY static_languages.lg_name_en',
                 'itemsProcFunc' => SJBR\StaticInfoTables\Hook\Backend\Form\FormDataProvider\TcaSelectItemsProcessor::class. '->translateLanguagesSelector',
-                'noIconsBelowSelect' => 1,
                 'size' => 1,
                 'minitems' => 0,
                 'maxitems' => 1,
index 587ad3e..056d960 100644 (file)
@@ -22,7 +22,7 @@ return array(
             'label' => 'LLL:EXT:lang/locallang_general.xlf:LGL.category',
             'config' => array(
                 'type' => 'select',
-                    'renderType' => 'selectSingle',
+                'renderType' => 'selectSingle',
                 'items' => array(
                     array('', '0', 'sysnote-type-0'),
                     array('LLL:EXT:sys_note/Resources/Private/Language/locallang_tca.xlf:sys_note.category.I.1', '1', 'sysnote-type-1'),
@@ -30,7 +30,8 @@ return array(
                     array('LLL:EXT:sys_note/Resources/Private/Language/locallang_tca.xlf:sys_note.category.I.4', '4', 'sysnote-type-4'),
                     array('LLL:EXT:sys_note/Resources/Private/Language/locallang_tca.xlf:sys_note.category.I.2', '2', 'sysnote-type-2')
                 ),
-                'default' => '0'
+                'default' => '0',
+                'showIconTable' => true,
             )
         ),
         'subject' => array(