[BUGFIX] Show thumbnail in list module for columns in palettes 44/57744/2
authorDavid Gurk <dgsammelbox-typo3org@yahoo.com>
Fri, 27 Apr 2018 13:55:35 +0000 (15:55 +0200)
committerMarkus Klein <markus.klein@typo3.org>
Wed, 1 Aug 2018 20:01:08 +0000 (22:01 +0200)
By replacing the palettes in showitem of types with their content,
the following condition can consider the columns within the palettes.

Resolves: #84885
Related: #26753
Releases: master, 8.7
Change-Id: I6561fc862cb4ed569ee886e4d070e9fba6a1654b
Reviewed-on: https://review.typo3.org/57744
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Markus Klein <markus.klein@typo3.org>
Tested-by: Markus Klein <markus.klein@typo3.org>
typo3/sysext/recordlist/Classes/RecordList/DatabaseRecordList.php
typo3/sysext/recordlist/Tests/Unit/RecordList/DatabaseRecordListTest.php [new file with mode: 0644]

index 5d50b9c..5831686 100644 (file)
@@ -979,7 +979,7 @@ class DatabaseRecordList extends AbstractDatabaseRecordList
                 if (!isset($GLOBALS['TCA'][$table]['types'][$type])) {
                     $type = isset($GLOBALS['TCA'][$table]['types'][0]) ? 0 : 1;
                 }
-                $visibleColumns = $GLOBALS['TCA'][$table]['types'][$type]['showitem'];
+                $visibleColumns = $this->getVisibleColumns($GLOBALS['TCA'][$table], $type);
 
                 if ($this->thumbs &&
                     trim($row[$thumbsCol]) &&
@@ -2356,6 +2356,35 @@ class DatabaseRecordList extends AbstractDatabaseRecordList
     }
 
     /**
+     * Flatten palettes into types showitem
+     *
+     * By replacing the palettes in showitem of a TCA type with each palette content, the fields within a palette
+     * can be considered as visible database columns for a backend form.
+     *
+     * @param array $tableTCA
+     * @param string $type
+     * @return string
+     */
+    protected function getVisibleColumns(array $tableTCA, string $type)
+    {
+        $visibleColumns = $tableTCA['types'][$type]['showitem'] ?? '';
+
+        if (strpos($visibleColumns, '--palette--') !== false) {
+            $matches = [];
+            preg_match_all('/--palette--\s*;[^;]*;\s*(\w+)/', $visibleColumns, $matches, PREG_SET_ORDER);
+            if (!empty($matches)) {
+                foreach ($matches as $palette) {
+                    $paletteColumns = $tableTCA['palettes'][$palette[1]]['showitem'] ?? '';
+                    $paletteColumns = rtrim($paletteColumns, ", \t\r\n");
+                    $visibleColumns = str_replace($palette[0], $paletteColumns, $visibleColumns);
+                }
+            }
+        }
+
+        return $visibleColumns;
+    }
+
+    /**
      * @return BaseScriptClass
      */
     protected function getModule()
diff --git a/typo3/sysext/recordlist/Tests/Unit/RecordList/DatabaseRecordListTest.php b/typo3/sysext/recordlist/Tests/Unit/RecordList/DatabaseRecordListTest.php
new file mode 100644 (file)
index 0000000..5561d16
--- /dev/null
@@ -0,0 +1,231 @@
+<?php
+declare(strict_types = 1);
+namespace TYPO3\CMS\Recordlist\Tests\Unit\RecordList;
+
+/*
+ * This file is part of the TYPO3 CMS project.
+ *
+ * It is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License, either version 2
+ * of the License, or any later version.
+ *
+ * For the full copyright and license information, please read the
+ * LICENSE.txt file that was distributed with this source code.
+ *
+ * The TYPO3 project - inspiring people to share!
+ */
+
+use TYPO3\CMS\Recordlist\RecordList\DatabaseRecordList;
+use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
+
+class DatabaseRecordListTest extends UnitTestCase
+{
+    /**
+     * @var DatabaseRecordList|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\TestingFramework\Core\AccessibleObjectInterface
+     */
+    protected $subject;
+
+    protected function setUp()
+    {
+        parent::setUp();
+
+        $this->subject = $this->getAccessibleMock(DatabaseRecordList::class, ['dummy'], [], '', false);
+    }
+
+    public function visibleColumnsDataProvider(): array
+    {
+        return [
+            'basicTest' => [
+                [
+                    'ctrl' => [
+                        'title' => 'LLL:EXT:frontend/Resources/Private/Language/locallang_tca.xlf:tt_content',
+                    ],
+                    'types' => [
+                        'bullets' => [
+                            'showitem' => '--div--;LABEL,--palette--;;general,bodytext;LABEL',
+                        ],
+                    ],
+                    'palettes' => [
+                        'general' => [
+                            'label' => 'Baz',
+                            'showitem' => 'CType;LABEL,colPos;LABEL',
+                        ],
+                    ],
+                ],
+                'bullets',
+                '--div--;LABEL,CType;LABEL,colPos;LABEL,bodytext;LABEL',
+            ],
+            'linebreaks' => [
+                [
+                    'ctrl' => [
+                        'title' => 'LLL:EXT:frontend/Resources/Private/Language/locallang_tca.xlf:tt_content',
+                    ],
+                    'types' => [
+                        'bullets' => [
+                            'showitem' => '--div--;LABEL,
+                            --palette--;;general,bodytext;LABEL',
+                        ],
+                    ],
+                    'palettes' => [
+                        'general' => [
+                            'label' => 'Baz',
+                            'showitem' => 'CType;LABEL,colPos;LABEL',
+                        ],
+                    ],
+                ],
+                'bullets',
+                '--div--;LABEL,
+                            CType;LABEL,colPos;LABEL,bodytext;LABEL',
+            ],
+            'spacesInShowItems' => [
+                [
+                    'ctrl' => [
+                        'title' => 'LLL:EXT:frontend/Resources/Private/Language/locallang_tca.xlf:tt_content',
+                    ],
+                    'types' => [
+                        'bullets' => [
+                            'showitem' => '--div-- ; LABEL , --palette-- ; ; general , bodytext ; LABEL',
+                        ],
+                    ],
+                    'palettes' => [
+                        'general' => [
+                            'label' => 'Baz',
+                            'showitem' => 'CType ; LABEL , colPos ; LABEL',
+                        ],
+                    ],
+                ],
+                'bullets',
+                '--div-- ; LABEL , CType ; LABEL , colPos ; LABEL , bodytext ; LABEL',
+            ],
+            'spacesInShowItemsAndLinebreaks' => [
+                [
+                    'ctrl' => [
+                        'title' => 'LLL:EXT:frontend/Resources/Private/Language/locallang_tca.xlf:tt_content',
+                    ],
+                    'types' => [
+                        'bullets' => [
+                            'showitem' => '--div-- ; LABEL ,
+                            --palette-- ; ; general , bodytext ; LABEL',
+                        ],
+                    ],
+                    'palettes' => [
+                        'general' => [
+                            'label' => 'Baz',
+                            'showitem' => 'CType ; LABEL , colPos ; LABEL',
+                        ],
+                    ],
+                ],
+                'bullets',
+                '--div-- ; LABEL ,
+                            CType ; LABEL , colPos ; LABEL , bodytext ; LABEL',
+            ],
+            'nonExistentPalette' => [
+                [
+                    'ctrl' => [
+                        'title' => 'LLL:EXT:frontend/Resources/Private/Language/locallang_tca.xlf:tt_content',
+                    ],
+                    'types' => [
+                        'bullets' => [
+                            'showitem' => '--div--;LABEL,--palette--;;iDoNotExist,bodytext;LABEL',
+                        ],
+                    ],
+                ],
+                'bullets',
+                '--div--;LABEL,,bodytext;LABEL',
+            ],
+            'trailingCommaInPalette' => [
+                [
+                    'ctrl' => [
+                        'title' => 'LLL:EXT:frontend/Resources/Private/Language/locallang_tca.xlf:tt_content',
+                    ],
+                    'types' => [
+                        'bullets' => [
+                            'showitem' => '--div--;LABEL,--palette--;;general,bodytext;LABEL',
+                        ],
+                    ],
+                    'palettes' => [
+                        'general' => [
+                            'label' => 'Baz',
+                            'showitem' => 'CType;LABEL,colPos;LABEL,',
+                        ],
+                    ],
+                ],
+                'bullets',
+                '--div--;LABEL,CType;LABEL,colPos;LABEL,bodytext;LABEL',
+            ],
+            'trailingSpaceInPalette' => [
+                [
+                    'ctrl' => [
+                        'title' => 'LLL:EXT:frontend/Resources/Private/Language/locallang_tca.xlf:tt_content',
+                    ],
+                    'types' => [
+                        'bullets' => [
+                            'showitem' => '--div--;LABEL,--palette--;;general,bodytext;LABEL',
+                        ],
+                    ],
+                    'palettes' => [
+                        'general' => [
+                            'label' => 'Baz',
+                            'showitem' => 'CType;LABEL,colPos;LABEL ',
+                        ],
+                    ],
+                ],
+                'bullets',
+                '--div--;LABEL,CType;LABEL,colPos;LABEL,bodytext;LABEL',
+            ],
+            'trailingTabInPalette' => [
+                [
+                    'ctrl' => [
+                        'title' => 'LLL:EXT:frontend/Resources/Private/Language/locallang_tca.xlf:tt_content',
+                    ],
+                    'types' => [
+                        'bullets' => [
+                            'showitem' => '--div--;LABEL,--palette--;;general,bodytext;LABEL',
+                        ],
+                    ],
+                    'palettes' => [
+                        'general' => [
+                            'label' => 'Baz',
+                            'showitem' => 'CType;LABEL,colPos;LABEL ',
+                        ],
+                    ],
+                ],
+                'bullets',
+                '--div--;LABEL,CType;LABEL,colPos;LABEL,bodytext;LABEL',
+            ],
+            'trailingLinebreakInPalette' => [
+                [
+                    'ctrl' => [
+                        'title' => 'LLL:EXT:frontend/Resources/Private/Language/locallang_tca.xlf:tt_content',
+                    ],
+                    'types' => [
+                        'bullets' => [
+                            'showitem' => '--div--;LABEL,--palette--;;general,bodytext;LABEL',
+                        ],
+                    ],
+                    'palettes' => [
+                        'general' => [
+                            'label' => 'Baz',
+                            'showitem' => 'CType;LABEL,colPos;LABEL
+                            ',
+                        ],
+                    ],
+                ],
+                'bullets',
+                '--div--;LABEL,CType;LABEL,colPos;LABEL,bodytext;LABEL',
+            ],
+        ];
+    }
+
+    /**
+     * @test
+     * @dataProvider visibleColumnsDataProvider
+     * @param array $tableTCA
+     * @param string $type
+     * @param string $expected
+     */
+    public function getVisibleColumns(array $tableTCA, string $type, string $expected)
+    {
+        $this->assertSame($expected, $this->subject->_callRef('getVisibleColumns', $tableTCA, $type));
+    }
+}