[BUGFIX] BEfunc getProcessedValue doesn't show record title for "group" 82/13082/9
authorGeorg Ringer <georg.ringer@gmail.com>
Sun, 23 Sep 2012 11:34:08 +0000 (13:34 +0200)
committerWouter Wolters <typo3@wouterwolters.nl>
Sun, 5 May 2013 13:16:33 +0000 (15:16 +0200)
In the list view relation fields using the type group (internal_type=db)
doesn't display the related value as expected. Instead, it shows
the UID of the relation. As these calls go through getProcessedValue,
the issue resolves the records by displaying the record titles correctly
in the TYPO3 backend.

Change-Id: I7d9cc8ec7f02e4a02518fcd14c81cc71f69b8ea7
Resolves: #21410
Releases: 6.2, 6.1, 6.0
Reviewed-on: https://review.typo3.org/13082
Reviewed-by: Wouter Wolters
Tested-by: Wouter Wolters
typo3/sysext/backend/Classes/Utility/BackendUtility.php
typo3/sysext/backend/Tests/Unit/Utility/BackendUtilityTest.php

index ef7d7b7..2d8721c 100644 (file)
@@ -2034,7 +2034,28 @@ class BackendUtility {
                                }
                                break;
                        case 'group':
-                               $l = implode(', ', GeneralUtility::trimExplode(',', $value, 1));
+                               // resolve the titles for DB records
+                               if ($theColConf['internal_type'] === 'db') {
+                                       $finalValues = array();
+                                       $relationTableName = $theColConf['allowed'];
+                                       $explodedValues = GeneralUtility::trimExplode(',', $value, TRUE);
+
+                                       foreach ($explodedValues as $explodedValue) {
+
+                                               if (MathUtility::canBeInterpretedAsInteger($explodedValue)) {
+                                                       $relationTableNameForField = $relationTableName;
+                                               } else {
+                                                       list($relationTableNameForField, $explodedValue) = self::splitTable_Uid($explodedValue);
+                                               }
+
+                                               $relationRecord = static::getRecordWSOL($relationTableNameForField, $explodedValue);
+                                               $finalValues[] = static::getRecordTitle($relationTableNameForField, $relationRecord);
+                                       }
+
+                                       $l = implode(', ', $finalValues);
+                               } else {
+                                       $l = implode(', ', GeneralUtility::trimExplode(',', $value, TRUE));
+                               }
                                break;
                        case 'check':
                                if (!is_array($theColConf['items']) || count($theColConf['items']) == 1) {
index 88986c2..67ec85b 100644 (file)
@@ -145,6 +145,35 @@ class BackendUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                $this->assertEquals('0', $this->fixture->getProcessedValue('tt_content', 'header', '0'));
        }
 
+       /**
+        * @test
+        */
+       public function getProcessedValueForGroup() {
+               $this->assertSame('1, 2', $this->fixture->getProcessedValue('tt_content', 'multimedia', '1,2'));
+       }
+
+       /**
+        * @test
+        */
+       public function getProcessedValueForGroupWithOneAllowedTable() {
+               /** @var \PHPUnit_Framework_MockObject_MockObject|Utility\BackendUtility $fixture */
+               $fixture = $this->getMock('TYPO3\\CMS\\Backend\\Utility\\BackendUtility', array('getRecordWSOL'));
+               $fixture->staticExpects($this->at(0))->method('getRecordWSOL')->will($this->returnValue(array('title' => 'Page 1')));
+               $fixture->staticExpects($this->at(1))->method('getRecordWSOL')->will($this->returnValue(array('title' => 'Page 2')));
+               $this->assertSame('Page 1, Page 2', $fixture->getProcessedValue('tt_content', 'pages', '1,2'));
+       }
+
+       /**
+        * @test
+        */
+       public function getProcessedValueForGroupWithMultipleAllowedTables() {
+               /** @var \PHPUnit_Framework_MockObject_MockObject|Utility\BackendUtility $fixture */
+               $fixture = $this->getMock('TYPO3\\CMS\\Backend\\Utility\\BackendUtility', array('getRecordWSOL'));
+               $fixture->staticExpects($this->at(0))->method('getRecordWSOL')->will($this->returnValue(array('title' => 'Page 1')));
+               $fixture->staticExpects($this->at(1))->method('getRecordWSOL')->will($this->returnValue(array('header' => 'Content 2')));
+               $this->assertSame('Page 1, Content 2', $fixture->getProcessedValue('sys_category', 'items', 'pages_1,tt_content_2'));
+       }
+
        /**
         * Tests concerning getCommenSelectFields
         */