[FEATURE] Override check/radio labels with TSConfig 59/29559/16
authorMathias Schreiber <mathias.schreiber@wmdb.de>
Mon, 29 Dec 2014 08:47:39 +0000 (09:47 +0100)
committerWouter Wolters <typo3@wouterwolters.nl>
Thu, 1 Jan 2015 19:03:07 +0000 (20:03 +0100)
Enable locallang override from TSConfig with reference (LLL:) or value.

Use the following instructions :
TCEFORM.[table name].[field].altLabels.[key]

For check fields, [key] is the index of the checkbox.
For radio fields, [key] is the value of the radio button.

Change-Id: I3e5ec9074c2b2429d983168994950e482b025d49
Resolves: #58033
Releases: master
Reviewed-on: http://review.typo3.org/29559
Reviewed-by: Benjamin Mack <benni@typo3.org>
Tested-by: Benjamin Mack <benni@typo3.org>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
typo3/sysext/backend/Classes/Form/Element/CheckboxElement.php
typo3/sysext/backend/Classes/Form/Element/RadioElement.php
typo3/sysext/core/Documentation/Changelog/master/Feature-58033-AltLabelsForFormEngineCheckboxAndRadioButtons.rst [new file with mode: 0644]

index c8e89f1..3e539c2 100644 (file)
@@ -59,11 +59,22 @@ class CheckboxElement extends AbstractFormElement {
                        $colWidth = floor(12 / $cols);
                        $colLeftover = 12 - $colWidth * $cols;
                        for ($counter = 0; $counter < $numberOfItems; $counter++) {
+                               // use "default" for typical single checkboxes
+                               $tsConfigKey = ($numberOfItems === 1 ? 'default' : $items[$counter][1]);
+                               // useful for e.g. pages.l18n_cfg, where there is no value set
+                               if ($tsConfigKey === '') {
+                                       $tsConfigKey = $counter;
+                               }
+                               if (isset($additionalInformation['fieldTSConfig']['altLabels.'][$tsConfigKey])) {
+                                       $label = $this->getLanguageService()->sL($additionalInformation['fieldTSConfig']['altLabels.'][$tsConfigKey]);
+                               } else {
+                                       $label = $items[$counter][0];
+                               }
                                if (!($counter % $cols)) {
                                        $item .= '<div class="row">';
                                }
                                $item .= '<div class="col-md-' . $colWidth . '">'
-                                       . $this->renderSingleCheckboxElement($items[$counter][0], $counter,  $formElementValue, $numberOfItems, $additionalInformation, $disabled)
+                                       . $this->renderSingleCheckboxElement($label, $counter,  $formElementValue, $numberOfItems, $additionalInformation, $disabled)
                                        . '</div>';
                                if ($counter % $cols + 1 == $cols) {
                                        $item .= ($colLeftover > 0 ? '<div class="col-md-' . $colLeftover . '"></div>' : '') . '</div>';
@@ -80,7 +91,18 @@ class CheckboxElement extends AbstractFormElement {
                        }
                } else {
                        for ($counter = 0; $counter < $numberOfItems; $counter++) {
-                               $item .=  $this->renderSingleCheckboxElement($items[$counter][0], $counter, $formElementValue, $numberOfItems, $additionalInformation, $disabled);
+                               // use "default" for typical single checkboxes
+                               $tsConfigKey = ($numberOfItems === 1 ? 'default' : $items[$counter][1]);
+                               // useful for e.g. pages.l18n_cfg, where there is no value set
+                               if ($tsConfigKey === '') {
+                                       $tsConfigKey = $counter;
+                               }
+                               if (isset($additionalInformation['fieldTSConfig']['altLabels.'][$tsConfigKey])) {
+                                       $label = $this->getLanguageService()->sL($additionalInformation['fieldTSConfig']['altLabels.'][$tsConfigKey]);
+                               } else {
+                                       $label = $items[$counter][0];
+                               }
+                               $item .=  $this->renderSingleCheckboxElement($label, $counter, $formElementValue, $numberOfItems, $additionalInformation, $disabled);
                        }
                }
                if (!$disabled) {
index c280868..61ab33d 100644 (file)
@@ -50,8 +50,15 @@ class RadioElement extends AbstractFormElement {
                }
 
                // Traverse the items, making the form elements
-               foreach ($selectedItems as $checkbox => $selectedItem) {
-                       $radioId = htmlspecialchars($additionalInformation['itemFormElID'] . '_' . $checkbox);
+               foreach ($selectedItems as $radioButton => $selectedItem) {
+                       if (isset($additionalInformation['fieldTSConfig']['altLabels.'][$radioButton])) {
+                               $label = $this->getLanguageService()->sL(
+                                       $additionalInformation['fieldTSConfig']['altLabels.'][$radioButton]
+                               );
+                       } else {
+                               $label =  $selectedItem[0];
+                       }
+                       $radioId = htmlspecialchars($additionalInformation['itemFormElID'] . '_' . $radioButton);
                        $radioOnClick = implode('', $additionalInformation['fieldChangeFunc']);
                        $radioChecked = (string)$selectedItem[1] === (string)$additionalInformation['itemFormElValue'] ? ' checked="checked"' : '';
                        $item .= '<div class="radio' . $disabled . '">'
@@ -67,7 +74,7 @@ class RadioElement extends AbstractFormElement {
                                . $disabled . ' '
                                . 'onclick="' . htmlspecialchars($radioOnClick) . '" '
                                . '/>'
-                               . htmlspecialchars($selectedItem[0])
+                               . htmlspecialchars($label)
                                . '</label>'
                        . '</div>';
                }
diff --git a/typo3/sysext/core/Documentation/Changelog/master/Feature-58033-AltLabelsForFormEngineCheckboxAndRadioButtons.rst b/typo3/sysext/core/Documentation/Changelog/master/Feature-58033-AltLabelsForFormEngineCheckboxAndRadioButtons.rst
new file mode 100644 (file)
index 0000000..a099842
--- /dev/null
@@ -0,0 +1,31 @@
+=================================================================================
+Feature: #58033 - Enable label override of checkbox and radio buttons by TSconfig
+=================================================================================
+
+Description
+-----------
+
+Use TSconfig to override labels of radio buttons and checkboxes used in FormEngine.
+
+For single checkboxes the key "default" is used:
+
+.. codeblock:: typoscript
+       TCEFORM.pages.hidden.altLabels.default = individual label
+
+.. codeblock:: typoscript
+       TCEFORM.pages.hidden.altLabels.default = LLL:path/to/languagefile.xlf:individualLabel
+
+For fields with multiple checkboxes, the value or the corresponding numeration (0,1,2,3) of the checkbox is used:
+
+.. codeblock:: typoscript
+       TCEFORM.pages.l18n_cfg.altLabels.0 = individual label for the first checkbox
+       TCEFORM.pages.l18n_cfg.altLabels.1 = individual label for the second checkbox
+
+The same functionality works on radio buttons, where the "key" is the value of the radio button.
+
+As seen in the example, hard-coded strings or references to language files are allowed.
+
+Impact
+------
+
+The feature enables even more customization for FormEngine for any custom crafted backend instance.