[BUGFIX] Allow RTE transformations in palettes 65/50465/2
authorJohannes Schlier <johannes.schlier@b13.de>
Mon, 31 Oct 2016 09:33:47 +0000 (10:33 +0100)
committerChristian Kuhn <lolli@schwarzbu.ch>
Mon, 31 Oct 2016 21:59:42 +0000 (22:59 +0100)
When having an RTE inside a palette (e.g. sys_file_reference
description field changed to a RTE field) then the RTE configuration
is not taken into account, thus it's not possible to do proper
transformations. All links are not working then.

The patch allows to parse the fields inside palettes as well.

Resolves: #60399
Resolves: #76745
Releases: master, 7.6
Change-Id: I0c4efc0a03682cd766a2a164cf7b2fa14cd7c1b9
Reviewed-on: https://review.typo3.org/50465
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/backend/Classes/Utility/BackendUtility.php
typo3/sysext/backend/Tests/Unit/Utility/BackendUtilityTest.php

index f18ea89..59ad922 100644 (file)
@@ -802,6 +802,25 @@ class BackendUtility
                 }
             }
 
+            // Add palette fields e.g. for a valid RTE transformation
+            $paletteFieldList = [];
+            foreach ($fieldList as $fieldData) {
+                list($pFieldName, $pAltTitle, $pPalette) = GeneralUtility::trimExplode(';', $fieldData);
+                if ($pPalette
+                    && isset($GLOBALS['TCA'][$table]['palettes'][$pPalette])
+                    && is_array($GLOBALS['TCA'][$table]['palettes'][$pPalette])
+                    && isset($GLOBALS['TCA'][$table]['palettes'][$pPalette]['showitem'])
+                ) {
+                    $paletteFields = GeneralUtility::trimExplode(',', $GLOBALS['TCA'][$table]['palettes'][$pPalette]['showitem'], true);
+                    foreach ($paletteFields as $paletteField) {
+                        if ($paletteField !== '--linebreak--') {
+                            $paletteFieldList[] = $paletteField;
+                        }
+                    }
+                }
+            }
+            $fieldList = array_merge($fieldList, $paletteFieldList);
+
             $altFieldList = [];
             // Traverse fields in types config and parse the configuration into a nice array:
             foreach ($fieldList as $k => $v) {
index 1d685ea..c4fc01f 100644 (file)
@@ -1075,4 +1075,278 @@ class BackendUtilityTest extends UnitTestCase
         $this->assertSame('24-03-16 00:00 (-1 day)', BackendUtility::dateTimeAge($GLOBALS['EXEC_TIME'] + 86400));
         $this->assertSame('24-03-16 (-1 day)', BackendUtility::dateTimeAge($GLOBALS['EXEC_TIME'] + 86400, 1, 'date'));
     }
+
+    ///////////////////////////////////////
+    // Tests concerning getTCAtypes
+    ///////////////////////////////////////
+
+    /**
+     * @test
+     */
+    public function getTCAtypesReturnsCorrectValuesDataProvider()
+    {
+        return [
+            'no input' => [
+                '', // table
+                [], // rec
+                '', // useFieldNameAsKey
+                null // expected
+            ],
+            'non-existant table' => [
+                'fooBar', // table
+                [], // rec
+                '', // useFieldNameAsKey
+                null // expected
+            ],
+            'Doktype=1: one simple field' => [
+                'pages',
+                [
+                    'uid' => '1',
+                    'doktype' => '1'
+                ],
+                false,
+                [
+                    0 => [
+                        'field' => 'title',
+                        'title' => null,
+                        'palette' => null,
+                        'spec' => [],
+                        'origString' => 'title'
+                    ]
+                ]
+            ],
+            'non-existant type given: Return for type 1' => [
+                'pages', // table
+                [
+                    'uid' => '1',
+                    'doktype' => '999'
+                ], // rec
+                '', // useFieldNameAsKey
+                [
+                    0 => [
+                        'field' => 'title',
+                        'title' => null,
+                        'palette' => null,
+                        'spec' => [],
+                        'origString' => 'title'
+                    ]
+                ] // expected
+            ],
+            'Doktype=1: one simple field, useFieldNameAsKey=true' => [
+                'pages',
+                [
+                    'uid' => '1',
+                    'doktype' => '1'
+                ],
+                true,
+                [
+                    'title' => [
+                        'field' => 'title',
+                        'title' => null,
+                        'palette' => null,
+                        'spec' => [],
+                        'origString' => 'title'
+                    ]
+                ]
+            ],
+            'Empty showitem Field' => [
+                'test',
+                [
+                    'uid' => '1',
+                    'fooBar' => '99'
+                ],
+                true,
+                [
+                    '' => [
+                        'field' => '',
+                        'title' => null,
+                        'palette' => null,
+                        'spec' => [],
+                        'origString' => ''
+                    ]
+                ]
+            ],
+            'RTE field within a palette' => [
+                'pages',
+                [
+                    'uid' => '1',
+                    'doktype' => '10',
+                ],
+                false,
+                [
+                    0 => [
+                        'field' => '--div--',
+                        'title' => 'General',
+                        'palette' => null,
+                        'spec' => [],
+                        'origString' => '--div--;General'
+                    ],
+                    1 => [
+                        'field' => '--palette--',
+                        'title' => 'Palette',
+                        'palette' => '123',
+                        'spec' => [],
+                        'origString' => '--palette--;Palette;123'
+                    ],
+                    2 => [
+                        'field' => 'title',
+                        'title' => null,
+                        'palette' => null,
+                        'spec' => [],
+                        'origString' => 'title'
+                    ],
+                    3 => [
+                        'field' => 'text',
+                        'title' => null,
+                        'palette' => null,
+                        'spec' => [
+                            'richtext' => 1,
+                            'rte_transform' => [
+                                'parameters' => [
+                                    0 => 'mode=ts_css'
+                                ]
+                            ]
+                        ],
+                        'origString' => 'text'
+                    ],
+                    4 => [
+                        'field' => 'select',
+                        'title' => 'Select field',
+                        'palette' => null,
+                        'spec' => [],
+                        'origString' => 'select;Select field'
+                    ]
+                ]
+            ],
+            'RTE field with more settings within a palette' => [
+                'pages',
+                [
+                    'uid' => 1,
+                    'doktype' => 2
+                ],
+                false,
+                [
+                    0 => [
+                        'field' => '--div--',
+                        'title' => 'General',
+                        'palette' => null,
+                        'spec' => [],
+                        'origString' => '--div--;General'
+                    ],
+                    1 => [
+                        'field' => '--palette--',
+                        'title' => 'RTE palette',
+                        'palette' => '456',
+                        'spec' => [],
+                        'origString' => '--palette--;RTE palette;456'
+                    ],
+                    2 => [
+                        'field' => 'text2',
+                        'title' => null,
+                        'palette' => null,
+                        'spec' => [
+                            'richtext' => 1,
+                            'rte_transform' => [
+                                'parameters' => [
+                                    0 => 'mode=fooBar,type=RTE'
+                                ]
+                            ]
+                        ],
+                        'origString' => 'text2'
+                    ]
+                ]
+            ]
+        ];
+    }
+
+    /**
+     * @test
+     * @dataProvider getTCAtypesReturnsCorrectValuesDataProvider
+     *
+     * @param string $table
+     * @param array $rec
+     * @param bool $useFieldNameAsKey
+     * @param array $expected
+     */
+    public function getTCAtypesReturnsCorrectValues($table, $rec, $useFieldNameAsKey, $expected)
+    {
+        $GLOBALS['TCA'] = [
+            'pages' => [
+                'ctrl' => [
+                    'type' => 'doktype'
+                ],
+                'columns' => [
+                    'title' => [
+                        'label' => 'Title test',
+                        'config' => [
+                            'type' => 'input'
+                        ]
+                    ],
+                    'text' => [
+                        'label' => 'RTE Text',
+                        'config' => [
+                            'type' => 'text',
+                            'cols' => 40,
+                            'rows' => 5
+                        ],
+                        'defaultExtras' => 'richtext:rte_transform[mode=ts_css]'
+                    ],
+                    'text2' => [
+                        'label' => 'RTE Text 2',
+                        'config' => [
+                            'type' => 'text',
+                            'cols' => 40,
+                            'rows' => 5
+                        ],
+                        'defaultExtras' => 'richtext:rte_transform[mode=fooBar,type=RTE]'
+                    ],
+                    'select' => [
+                        'label' => 'Select test',
+                        'config' => [
+                            'items' => [
+                                ['Please select', 0],
+                                ['Option 1', 1],
+                                ['Option 2', 2]
+                            ]
+                        ],
+                        'maxitems' => 1,
+                        'renderType' => 'selectSingle'
+                    ]
+                ],
+                'types' => [
+                    '1' => [
+                        'showitem' => 'title'
+                    ],
+                    '2' => [
+                        'showitem' => '--div--;General,--palette--;RTE palette;456'
+                    ],
+                    '10' => [
+                        'showitem' => '--div--;General,--palette--;Palette;123,title'
+                    ],
+                    '14' => [
+                        'showitem' => '--div--;General,title'
+                    ]
+                ],
+                'palettes' => [
+                    '123' => [
+                        'showitem' => 'text,select;Select field'
+                    ],
+                    '456' => [
+                        'showitem' => 'text2'
+                    ]
+                ]
+            ],
+            'test' => [
+                'ctrl' => [
+                    'type' => 'fooBar'
+                ],
+                'types' => [
+                    '99' => [ 'showitem' => '']
+                ]
+            ]
+        ];
+
+        $return = BackendUtility::getTCAtypes($table, $rec, $useFieldNameAsKey);
+        $this->assertSame($expected, $return);
+    }
 }