[BUGFIX] Incorrect grouping of exclude fields in translated backend 07/20507/3
authorPhilipp Gampe <philipp.gampe@typo3.org>
Thu, 2 May 2013 15:44:57 +0000 (17:44 +0200)
committerJigal van Hemert <jigal.van.hemert@typo3.org>
Sun, 16 Jun 2013 10:23:06 +0000 (12:23 +0200)
If you use the backend in a language other than English, then the
grouping of the exclude fields in the be_group record is messed up when
flexform fields are included.

E.g. in a German backend, all tt_content fields are grouped below pages.

Sort the table names beforehand and afterwards all fields inside each
table.
Besides the patch converts some variables names into meaningful ones.

Fixes: #47839
Related: #34098
Releases: 6.2, 6.1, 6.0, 4.7, 4.5
Change-Id: I28ebc69d5cfc0316bdf44558276d3e939d011c2d
Reviewed-on: https://review.typo3.org/20507
Reviewed-by: Jigal van Hemert
Tested-by: Jigal van Hemert
typo3/sysext/backend/Classes/Utility/BackendUtility.php
typo3/sysext/backend/Tests/Unit/Utility/BackendUtilityTest.php

index 1ea2cf9..626ae55 100644 (file)
@@ -443,24 +443,33 @@ class BackendUtility {
         * @return array Array of arrays with excludeFields (fieldname, table:fieldname) from all TCA entries and from FlexForms (fieldname, table:extkey;sheetname;fieldname)
         */
        static public function getExcludeFields() {
+               $finalExcludeArray = array();
+
                // All TCA keys
-               $theExcludeArray = array();
-               $tc_keys = array_keys($GLOBALS['TCA']);
-               foreach ($tc_keys as $table) {
+               $tableNamesFromTca = array_keys($GLOBALS['TCA']);
+               // Fetch translations for table names
+               foreach ($tableNamesFromTca as $table) {
                        // Load table
                        \TYPO3\CMS\Core\Utility\GeneralUtility::loadTCA($table);
+                       $tableNamesFromTca[$table] = $GLOBALS['LANG']->sl($GLOBALS['TCA'][$table]['ctrl']['title']);
+               }
+               // Sort by translations
+               asort($tableNamesFromTca);
+               foreach ($tableNamesFromTca as $table => $translatedTable) {
+                       $excludeArrayTable = array();
+
                        // All field names configured and not restricted to admins
                        if (is_array($GLOBALS['TCA'][$table]['columns'])
                                        && empty($GLOBALS['TCA'][$table]['ctrl']['adminOnly'])
                                        && (empty($GLOBALS['TCA'][$table]['ctrl']['rootLevel']) || !empty($GLOBALS['TCA'][$table]['ctrl']['security']['ignoreRootLevelRestriction']))
                        ) {
-                               $f_keys = array_keys($GLOBALS['TCA'][$table]['columns']);
-                               foreach ($f_keys as $field) {
+                               $fieldKeys = array_keys($GLOBALS['TCA'][$table]['columns']);
+                               foreach ($fieldKeys as $field) {
                                        if ($GLOBALS['TCA'][$table]['columns'][$field]['exclude']) {
-                                               // Get human readable names of fields and table
-                                               $Fname = $GLOBALS['LANG']->sl($GLOBALS['TCA'][$table]['ctrl']['title']) . ': ' . $GLOBALS['LANG']->sl($GLOBALS['TCA'][$table]['columns'][$field]['label']);
+                                               // Get human readable names of fields
+                                               $translatedField = $GLOBALS['LANG']->sl($GLOBALS['TCA'][$table]['columns'][$field]['label']);
                                                // Add entry
-                                               $theExcludeArray[] = array($Fname, $table . ':' . $field);
+                                               $excludeArrayTable[] = array($translatedTable . ': ' . $translatedField, $table . ':' . $field);
                                        }
                                }
                        }
@@ -487,15 +496,19 @@ class BackendUtility {
                                                        }
                                                        $fieldLabel = !empty($field['TCEforms']['label']) ? $GLOBALS['LANG']->sl($field['TCEforms']['label']) : $fieldName;
                                                        $fieldIdent = $table . ':' . $tableField . ';' . $extIdent . ';' . $sheetName . ';' . $fieldName;
-                                                       $theExcludeArray[] = array(trim(($labelPrefix . ' ' . $extTitle), ': ') . ': ' . $fieldLabel, $fieldIdent);
+                                                       $excludeArrayTable[] = array(trim(($labelPrefix . ' ' . $extTitle), ': ') . ': ' . $fieldLabel, $fieldIdent);
                                                }
                                        }
                                }
                        }
+                       // Sort fields by the translated value
+                       if (count($excludeArrayTable) > 0) {
+                               usort($excludeArrayTable, array('TYPO3\\CMS\\Backend\\Form\\FlexFormsHelper', 'compareArraysByFirstValue'));
+                               $finalExcludeArray = array_merge($finalExcludeArray, $excludeArrayTable);
+                       }
                }
-               // Sort fields by label
-               usort($theExcludeArray, array('TYPO3\\CMS\\Backend\\Form\\FlexFormsHelper', 'compareArraysByFirstValue'));
-               return $theExcludeArray;
+
+               return $finalExcludeArray;
        }
 
        /**
index 3b5965b..104b5af 100644 (file)
@@ -551,6 +551,115 @@ class BackendUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                                ),
                                array()
                        ),
+                       'getExcludeFields sorts tables and properties with flexform fields properly' => array(
+                               array(
+                                       'tx_foo' => array(
+                                               'ctrl' => array(
+                                                       'title' => 'foo'
+                                               ),
+                                               'columns' => array(
+                                                       'foo' => array(
+                                                               'label' => 'foo',
+                                                               'exclude' => 1
+                                                       ),
+                                                       'bar' => array(
+                                                               'label' => 'bar',
+                                                               'exclude' => 1
+                                                       ),
+                                                       'abarfoo' => array(
+                                                               'label' => 'abarfoo',
+                                                               'config' => array(
+                                                                       'type' => 'flex',
+                                                                       'ds' => array(
+                                                                               '*,dummy' => '<?xml version="1.0" encoding="utf-8"?>
+<T3DataStructure>
+       <sheets>
+               <sGeneral>
+                       <ROOT>
+                               <type>array</type>
+                               <el>
+                                       <xmlTitle>
+                                               <TCEforms>
+                                                       <exclude>1</exclude>
+                                                       <label>The Title:</label>
+                                                       <config>
+                                                               <type>input</type>
+                                                               <size>48</size>
+                                                       </config>
+                                               </TCEforms>
+                                       </xmlTitle>
+                               </el>
+                       </ROOT>
+               </sGeneral>
+       </sheets>
+</T3DataStructure>'
+                                                                       )
+                                                               )
+                                                       )
+                                               )
+                                       ),
+                                       'tx_foobar' => array(
+                                               'ctrl' => array(
+                                                       'title' => 'foobar'
+                                               ),
+                                               'columns' => array(
+                                                       'foo' => array(
+                                                               'label' => 'foo',
+                                                               'exclude' => 1
+                                                       ),
+                                                       'bar' => array(
+                                                               'label' => 'bar',
+                                                               'exclude' => 1
+                                                       )
+                                               )
+                                       ),
+                                       'tx_bar' => array(
+                                               'ctrl' => array(
+                                                       'title' => 'bar'
+                                               ),
+                                               'columns' => array(
+                                                       'foo' => array(
+                                                               'label' => 'foo',
+                                                               'exclude' => 1
+                                                       ),
+                                                       'bar' => array(
+                                                               'label' => 'bar',
+                                                               'exclude' => 1
+                                                       )
+                                               )
+                                       )
+                               ),
+                               array(
+                                       array(
+                                               'bar: bar',
+                                               'tx_bar:bar'
+                                       ),
+                                       array(
+                                               'bar: foo',
+                                               'tx_bar:foo'
+                                       ),
+                                       array(
+                                               'abarfoo dummy: The Title:',
+                                               'tx_foo:abarfoo;dummy;sGeneral;xmlTitle'
+                                       ),
+                                       array(
+                                               'foo: bar',
+                                               'tx_foo:bar'
+                                       ),
+                                       array(
+                                               'foo: foo',
+                                               'tx_foo:foo'
+                                       ),
+                                       array(
+                                               'foobar: bar',
+                                               'tx_foobar:bar'
+                                       ),
+                                       array(
+                                               'foobar: foo',
+                                               'tx_foobar:foo'
+                                       ),
+                               )
+                       )
                );
        }