[BUGFIX] Multiple values not displayed for simple items lists
authorFrancois Suter <francois@typo3.org>
Fri, 28 Oct 2011 12:09:00 +0000 (14:09 +0200)
committerFrancois Suter <francois@typo3.org>
Fri, 16 Dec 2011 13:12:33 +0000 (14:12 +0100)
t3lib_BEfunc::getProcessedValue() is used throughout the Core to
transform values stored as indices into human-readable values.

However for select-type fields based on a list of items
(and not a foreign table) where multiple selections are possible,
t3lib_BEfunc::getProcessedValue() fails to display anything.
This is due to t3lib_BEfunc::getLabelFromItemlist(),
being unable to handle several values.

This patch introduces a new method to avoid breaking compatibility.

Change-Id: I074099cd5fc06a346a86246bdf7620ebdc7b18cb
Resolves: #31374
Releases: 4.7, 4.6, 4.5
Reviewed-on: http://review.typo3.org/6379
Reviewed-by: Björn Pedersen
Reviewed-by: Markus Klein
Tested-by: Markus Klein
Reviewed-by: Francois Suter
Tested-by: Francois Suter
t3lib/class.t3lib_befunc.php

index fe93995..9aff859 100644 (file)
@@ -1794,6 +1794,41 @@ final class t3lib_BEfunc {
        }
 
        /**
+        * Splits the given key with commas and returns the list of all the localized items labels, separated by a comma.
+        * NOTE: this does not take itemsProcFunc into account
+        *
+        * @static
+        * @param string $table Table name, present in TCA
+        * @param string $column Field name
+        * @param string $key Key or comma-separated list of keys.
+        * @return string Comma-separated list of localized labels
+        */
+       public static function getLabelsFromItemsList($table, $column, $key) {
+               $labels = array();
+               $values = t3lib_div::trimExplode(',', $key, TRUE);
+               if (count($values) > 0) {
+                               // Load full TCA for $table
+                       t3lib_div::loadTCA($table);
+                               // Check if there is an "items" array
+                       if (is_array($GLOBALS['TCA'][$table]) && is_array($GLOBALS['TCA'][$table]['columns'][$column]) && is_array($GLOBALS['TCA'][$table]['columns'][$column]['config']['items'])) {
+                                       // Loop on all selected values
+                               foreach ($values as $aValue) {
+                                       foreach ($GLOBALS['TCA'][$table]['columns'][$column]['config']['items'] as $itemConfiguration) {
+                                                       // Loop on all available items
+                                                       // Keep matches and move on to next value
+                                               if ($aValue == $itemConfiguration[1]) {
+                                                       $labels[] = $GLOBALS['LANG']->sL($itemConfiguration[0]);
+                                                       break;
+                                               }
+                                       }
+                               }
+
+                       }
+               }
+               return implode(', ', $labels);
+       }
+
+       /**
         * Returns the label-value for fieldname $col in table, $table
         * If $printAllWrap is set (to a "wrap") then it's wrapped around the $col value IF THE COLUMN $col DID NOT EXIST in TCA!, eg. $printAllWrap = '<strong>|</strong>' and the fieldname was 'not_found_field' then the return value would be '<strong>not_found_field</strong>'
         *
@@ -2001,8 +2036,8 @@ final class t3lib_BEfunc {
                                                        $l = 'N/A';
                                                }
                                        } else {
-                                               $l = self::getLabelFromItemlist($table, $col, $value);
-                                               $l = $GLOBALS['LANG']->sL($l);
+                                               $l = self::getLabelsFromItemsList($table, $col, $value);
+
                                                if ($theColConf['foreign_table'] && !$l && $GLOBALS['TCA'][$theColConf['foreign_table']]) {
                                                        if ($noRecordLookup) {
                                                                $l = $value;