[BUGFIX] Use overridden field label in list view 05/59505/6
authorGeorg Ringer <georg.ringer@gmail.com>
Mon, 21 Jan 2019 10:41:31 +0000 (11:41 +0100)
committerBenni Mack <benni@typo3.org>
Wed, 30 Jan 2019 05:47:30 +0000 (06:47 +0100)
If a label of a table column is overridden by TsConfig
(TCEFORM.<table>.<column>.label), the new value
must also be used in the list view:

- header of the table rendering
- list of "set fields"

Resolves: #87484
Releases: master, 9.5
Change-Id: I8eafd1f2878b571edd1e5a30b28b0d5330b9b5d0
Reviewed-on: https://review.typo3.org/59505
Reviewed-by: Josef Glatz <josef.glatz@typo3.org>
Tested-by: Josef Glatz <josef.glatz@typo3.org>
Tested-by: TYPO3com <noreply@typo3.com>
Reviewed-by: Richard Haeser <richard@maxserv.com>
Tested-by: Riccardo De Contardi <erredeco@gmail.com>
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
typo3/sysext/recordlist/Classes/RecordList/DatabaseRecordList.php

index 26026a8..566a1d4 100644 (file)
@@ -1567,6 +1567,9 @@ class DatabaseRecordList
      */
     public function renderListHeader($table, $currentIdList)
     {
+        $tsConfig = BackendUtility::getPagesTSconfig($this->id);
+        $tsConfigOfTable = is_array($tsConfig['TCEFORM.'][$table . '.']) ? $tsConfig['TCEFORM.'][$table . '.'] : null;
+
         $lang = $this->getLanguageService();
         // Init:
         $theData = [];
@@ -1732,8 +1735,22 @@ class DatabaseRecordList
                     // at the end
                     $sortLabel = BackendUtility::getItemLabel($table, $fCol);
                     if ($sortLabel !== null) {
-                        $sortLabel = htmlspecialchars($lang->sL($sortLabel));
-                        $sortLabel = rtrim(trim($sortLabel), ':');
+                        $sortLabel = rtrim(trim($lang->sL($sortLabel)), ':');
+
+                        // Field label
+                        $fieldTSConfig = [];
+                        if (isset($tsConfigOfTable[$fCol . '.'])
+                            && is_array($tsConfigOfTable[$fCol . '.'])
+                        ) {
+                            $fieldTSConfig = $tsConfigOfTable[$fCol . '.'];
+                        }
+                        if (!empty($fieldTSConfig['label'])) {
+                            $sortLabel = $lang->sL($fieldTSConfig['label']);
+                        }
+                        if (!empty($fieldTSConfig['label.'][$lang->lang])) {
+                            $sortLabel = $lang->sL($fieldTSConfig['label.'][$lang->lang]);
+                        }
+                        $sortLabel = htmlspecialchars($sortLabel);
                     } else {
                         // No TCA field, only output the $fCol variable with square brackets []
                         $sortLabel = htmlspecialchars($fCol);
@@ -2512,14 +2529,28 @@ class DatabaseRecordList
                 $checkAllChecked = false;
                 $checked = '';
             }
+
             // Field label
-            $fieldLabel = is_array($GLOBALS['TCA'][$table]['columns'][$fieldName])
-                ? rtrim($lang->sL($GLOBALS['TCA'][$table]['columns'][$fieldName]['label']), ':')
-                : '';
+            $fieldTSConfig = [];
+            $fieldLabel = '';
+            if (isset($tsConfigOfTable[$fieldName . '.'])
+                && is_array($tsConfigOfTable[$fieldName . '.'])
+            ) {
+                $fieldTSConfig = $tsConfigOfTable[$fieldName . '.'];
+            }
+            if (!empty($fieldTSConfig['label'])) {
+                $fieldLabel = $fieldTSConfig['label'];
+            }
+            if (!empty($fieldTSConfig['label.'][$lang->lang])) {
+                $fieldLabel = $fieldTSConfig['label.'][$lang->lang];
+            }
+
+            $fieldLabel = $fieldLabel ?: BackendUtility::getItemLabel($table, $fieldName);
+
             $checkboxes[] = '<tr><td class="col-checkbox"><input type="checkbox" id="check-' . $fieldName . '" name="displayFields['
                 . $table . '][]" value="' . $fieldName . '" ' . $checked
                 . ($fieldName === $this->fieldArray[0] ? ' disabled="disabled"' : '') . '></td><td class="col-title">'
-                . '<label class="label-block" for="check-' . $fieldName . '">' . htmlspecialchars($fieldLabel) . ' <span class="text-muted text-monospace">[' . htmlspecialchars($fieldName) . ']</span></label></td></tr>';
+                . '<label class="label-block" for="check-' . $fieldName . '">' . htmlspecialchars($lang->sL($fieldLabel)) . ' <span class="text-muted text-monospace">[' . htmlspecialchars($fieldName) . ']</span></label></td></tr>';
         }
         // Table with the field selector::
         $content = $formElements[0] . '