Commit 723b023e authored by Philipp Gampe's avatar Philipp Gampe Committed by Helmut Hummel
Browse files

[BUGFIX] Incorrect grouping of exclude fields in translated backend

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/20427
Reviewed-by: Nicole Cordes
Tested-by: Nicole Cordes
Reviewed-by: Philipp Gampe
Tested-by: Philipp Gampe
Reviewed-by: Helmut Hummel
Tested-by: Helmut Hummel
parent 69508dc7
......@@ -443,22 +443,31 @@ 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) {
$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);
}
}
}
......@@ -485,15 +494,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;
}
/**
......
......@@ -519,6 +519,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'
),
)
)
);
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment