[!!!][TASK] Remove RTE "modes" option in TCA 22/46122/9
authorBenni Mack <benni@typo3.org>
Wed, 20 Jan 2016 22:03:46 +0000 (23:03 +0100)
committerChristian Kuhn <lolli@schwarzbu.ch>
Fri, 22 Jan 2016 17:19:41 +0000 (18:19 +0100)
It's ts_css anyways all the time through the overruleMode
option, which should be used anyway for the time being (as this option
still exists).

Resolves: #72856
Releases: master
Change-Id: If96f1c0faddf9b258fa3a60f4904cd48eb3ca854
Reviewed-on: https://review.typo3.org/46122
Reviewed-by: Frank Nägler <frank.naegler@typo3.org>
Tested-by: Frank Nägler <frank.naegler@typo3.org>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/core/Classes/DataHandling/DataHandler.php
typo3/sysext/core/Classes/Migrations/TcaMigration.php
typo3/sysext/core/Configuration/TCA/sys_news.php
typo3/sysext/core/Documentation/Changelog/master/Deprecation-72856-RemovedRTEModesOption.rst [new file with mode: 0644]
typo3/sysext/core/Tests/Unit/Migrations/TcaMigrationTest.php
typo3/sysext/css_styled_content/Configuration/TCA/Overrides/tt_content.php
typo3/sysext/fluid_styled_content/Configuration/TCA/Overrides/tt_content.php
typo3/sysext/rtehtmlarea/Classes/Form/Element/RichTextElement.php

index 485269c..260fca1 100644 (file)
@@ -1552,7 +1552,7 @@ class DataHandler
      * @param string $value Value to transform.
      * @param string $table The table name
      * @param string $field The field name
-     * @param array $defaultExtras Default extras configuration of this field - typically "richtext:rte_transform[mode=ts_css]"
+     * @param array $defaultExtras Default extras configuration of this field - typically "richtext:rte_transform"
      * @param array $thisConfig Configuration for RTEs; A mix between TSconfig and others. Configuration for additional transformation information
      * @param int $pid PID value of record (true parent page id)
      * @return string Transformed content
@@ -1560,15 +1560,11 @@ class DataHandler
     protected function transformRichtextContentToDatabase($value, $table, $field, $defaultExtras, $thisConfig, $pid)
     {
         if ($defaultExtras['rte_transform']) {
-            $parameters = BackendUtility::getSpecConfParametersFromArray($defaultExtras['rte_transform']['parameters']);
-            // There must be a mode set for transformation, this is typically 'ts_css'
-            if ($parameters['mode']) {
-                // Initialize transformation:
-                $parseHTML = GeneralUtility::makeInstance(RteHtmlParser::class);
-                $parseHTML->init($table . ':' . $field, $pid);
-                // Perform transformation:
-                $value = $parseHTML->RTE_transform($value, $defaultExtras, 'db', $thisConfig);
-            }
+            // Initialize transformation:
+            $parseHTML = GeneralUtility::makeInstance(RteHtmlParser::class);
+            $parseHTML->init($table . ':' . $field, $pid);
+            // Perform transformation:
+            $value = $parseHTML->RTE_transform($value, $defaultExtras, 'db', $thisConfig);
         }
         return $value;
     }
index 86a0b04..2401618 100644 (file)
@@ -52,6 +52,7 @@ class TcaMigration
         $tca = $this->migrateSelectFieldRenderType($tca);
         $tca = $this->migrateSelectFieldIconTable($tca);
         $tca = $this->migrateElementBrowserWizardToLinkHandler($tca);
+        $tca = $this->migrateDefaultExtrasRteTransFormOptions($tca);
         // @todo: if showitem/defaultExtras wizards[xy] is migrated to columnsOverrides here, enableByTypeConfig could be dropped
         return $tca;
     }
@@ -643,4 +644,70 @@ class TcaMigration
         }
         return $tca;
     }
+
+    /**
+     * Migrate defaultExtras "richtext:rte_transform[mode=ts_css]" and similar stuff like
+     * "richtext:rte_transform[mode=ts_css]" to "richtext:rte_transform"
+     *
+     * @param array $tca
+     * @return array Migrated TCA
+     */
+    protected function migrateDefaultExtrasRteTransFormOptions(array $tca)
+    {
+        foreach ($tca as $table => &$tableDefinition) {
+            if (!isset($tableDefinition['columns']) || !is_array($tableDefinition['columns'])) {
+                continue;
+            }
+            foreach ($tableDefinition['columns'] as $fieldName => &$fieldConfig) {
+                if (isset($fieldConfig['defaultExtras'])) {
+                    $oldValue = $fieldConfig['defaultExtras'];
+                    $fieldConfig['defaultExtras'] = preg_replace(
+                        '/richtext(\[([^\]]*)\])*:rte_transform(\[([^\]]*)\])/',
+                        'richtext${1}:rte_transform',
+                        $fieldConfig['defaultExtras'],
+                        -1,
+                        $replacementCount
+                    );
+                    if ($replacementCount) {
+                        $this->messages[] = 'rte_transform options are deprecated. String "' . $oldValue . '" in TCA'
+                            . ' ' . $table . '[\'columns\'][\'' . $fieldName . '\'][\'defaultExtras\'] was changed to "'
+                            . $fieldConfig['defaultExtras'] . '"';
+                    }
+                }
+            }
+        }
+
+        foreach ($tca as $table => &$tableDefinition) {
+            if (!isset($tableDefinition['types']) || !is_array($tableDefinition['types'])) {
+                continue;
+            }
+            foreach ($tableDefinition['types'] as $typeName => &$typeArray) {
+                if (!isset($typeArray['columnsOverrides']) || !is_array($typeArray['columnsOverrides'])) {
+                    continue;
+                }
+                foreach ($typeArray['columnsOverrides'] as $fieldName => &$fieldConfig) {
+                    if (isset($fieldConfig['defaultExtras'])) {
+                        $oldValue = $fieldConfig['defaultExtras'];
+                        $fieldConfig['defaultExtras'] = preg_replace(
+                            '/richtext(\[([^\]]*)\])*:rte_transform(\[([^\]]*)\])/',
+                            'richtext${1}:rte_transform',
+                            $fieldConfig['defaultExtras'],
+                            -1,
+                            $replacementCount
+                        );
+                        if ($replacementCount) {
+                            $this->messages[] = 'rte_transform options are deprecated. String "'
+                                . $oldValue . '" in TCA'
+                                . ' ' . $table . '[\'types\'][\'' . $typeName
+                                . '\'][\'columnsOverrides\'][\'' . $fieldName
+                                . '\'][\'defaultExtras\']' .
+                                ' was changed to "' . $fieldConfig['defaultExtras'] . '"';
+                        }
+                    }
+                }
+            }
+        }
+
+        return $tca;
+    }
 }
index 6fa930f..23a55f8 100644 (file)
@@ -79,7 +79,7 @@ return array(
                     )
                 )
             ),
-            'defaultExtras' => 'richtext:rte_transform[mode=ts_css]',
+            'defaultExtras' => 'richtext:rte_transform',
         )
     ),
     'types' => array(
diff --git a/typo3/sysext/core/Documentation/Changelog/master/Deprecation-72856-RemovedRTEModesOption.rst b/typo3/sysext/core/Documentation/Changelog/master/Deprecation-72856-RemovedRTEModesOption.rst
new file mode 100644 (file)
index 0000000..e059feb
--- /dev/null
@@ -0,0 +1,22 @@
+================================================
+Deprecation: #72856 - Removed RTE "modes" option
+================================================
+
+Description
+===========
+
+The RTE "modes" option that was added to a RTE enabled TCA field in the "defaultExtras" section was removed.
+
+The RTE is now loaded via the configuration from TSconfig, usually set by the "modes" or the "overruleMode" (used by default), and loaded even without the RTE mode set in the TCA field defaultExtras section.
+
+
+Impact
+======
+
+Extension authors do not need to set the defaultExtras "mode=ts_css" parameter explicitly.
+
+
+Migration
+=========
+
+When configuring a RTE field in a TYPO3 extension the defaultExtras part should bet set to ``richtext:rte_transform`` instead of  ``richtext:rte_transform[mode=ts_css]`` in order to render the RTE.
\ No newline at end of file
index 2d97eb3..f3fab06 100644 (file)
@@ -1025,4 +1025,362 @@ class TcaMigrationTest extends UnitTestCase
         $subject = new TcaMigration();
         $this->assertEquals($expected, $subject->migrate($input));
     }
+
+    /**
+     * @return array
+     */
+    public function migrateRemovesRteTransformOptionsDataProvider()
+    {
+        return [
+            'remove empty options in columns' => [
+                [
+                    // Given config section
+                    'aTable' => [
+                        'columns' => [
+                            'aField' => [
+                                'defaultExtras' => 'richtext:rte_transform[]'
+                            ]
+                        ]
+                    ]
+                ],
+                [
+                    // Expected config section
+                    'aTable' => [
+                        'columns' => [
+                            'aField' => [
+                                'defaultExtras' => 'richtext:rte_transform'
+                            ]
+                        ]
+                    ]
+                ],
+            ],
+            'remove nothing in columns' => [
+                [
+                    'aTable' => [
+                        'columns' => [
+                            'aField' => [
+                                'defaultExtras' => 'richtext:rte_transform'
+                            ]
+                        ]
+                    ]
+                ],
+                [
+                    'aTable' => [
+                        'columns' => [
+                            'aField' => [
+                                'defaultExtras' => 'richtext:rte_transform'
+                            ]
+                        ]
+                    ]
+                ],
+            ],
+            'remove mode in columns' => [
+                [
+                    'aTable' => [
+                        'columns' => [
+                            'aField' => [
+                                'defaultExtras' => 'richtext:rte_transform[mode=ts_css]'
+                            ]
+                        ]
+                    ]
+                ],
+                [
+                    'aTable' => [
+                        'columns' => [
+                            'aField' => [
+                                'defaultExtras' => 'richtext:rte_transform'
+                            ]
+                        ]
+                    ]
+                ],
+            ],
+            'remove flag and mode in columns' => [
+                [
+                    'aTable' => [
+                        'columns' => [
+                            'aField' => [
+                                'defaultExtras' => 'richtext:rte_transform[flag=rte_enabled|mode=ts_css]'
+                            ]
+                        ]
+                    ]
+                ],
+                [
+                    'aTable' => [
+                        'columns' => [
+                            'aField' => [
+                                'defaultExtras' => 'richtext:rte_transform'
+                            ]
+                        ]
+                    ]
+                ],
+            ],
+            'remove flag and mode in columns with array notation' => [
+                [
+                    'aTable' => [
+                        'columns' => [
+                            'aField' => [
+                                'defaultExtras' => 'richtext[]:rte_transform[flag=rte_enabled|mode=ts_css]'
+                            ]
+                        ]
+                    ]
+                ],
+                [
+                    'aTable' => [
+                        'columns' => [
+                            'aField' => [
+                                'defaultExtras' => 'richtext[]:rte_transform'
+                            ]
+                        ]
+                    ]
+                ],
+            ],
+            'remove flag and mode in columns with array notation and index' => [
+                [
+                    'aTable' => [
+                        'columns' => [
+                            'aField' => [
+                                'defaultExtras' => 'richtext[*]:rte_transform[flag=rte_enabled|mode=ts_css]'
+                            ]
+                        ]
+                    ]
+                ],
+                [
+                    'aTable' => [
+                        'columns' => [
+                            'aField' => [
+                                'defaultExtras' => 'richtext[*]:rte_transform'
+                            ]
+                        ]
+                    ]
+                ],
+            ],
+            'remove flag and mode in columns with array notation and index and option list' => [
+                [
+                    'aTable' => [
+                        'columns' => [
+                            'aField' => [
+                                'defaultExtras' => 'richtext[cut|copy|paste]:rte_transform[flag=rte_enabled|mode=ts_css]'
+                            ]
+                        ]
+                    ]
+                ],
+                [
+                    'aTable' => [
+                        'columns' => [
+                            'aField' => [
+                                'defaultExtras' => 'richtext[cut|copy|paste]:rte_transform'
+                            ]
+                        ]
+                    ]
+                ],
+            ],
+            'remove empty options in columnsOverrides' => [
+                [
+                    'aTable' => [
+                        'types' => [
+                            'aType' => [
+                                'columnsOverrides' => [
+                                    'aField' => [
+                                        'defaultExtras' => 'richtext:rte_transform[]'
+                                    ]
+                                ]
+                            ]
+                        ]
+                    ]
+                ],
+                [
+                    'aTable' => [
+                        'types' => [
+                            'aType' => [
+                                'columnsOverrides' => [
+                                    'aField' => [
+                                        'defaultExtras' => 'richtext:rte_transform'
+                                    ]
+                                ]
+                            ]
+                        ]
+                    ]
+                ],
+            ],
+            'remove nothing in columnsOverrides' => [
+                [
+                    'aTable' => [
+                        'types' => [
+                            'aType' => [
+                                'columnsOverrides' => [
+                                    'aField' => [
+                                        'defaultExtras' => 'richtext:rte_transform'
+                                    ]
+                                ]
+                            ]
+                        ]
+                    ]
+                ],
+                [
+                    'aTable' => [
+                        'types' => [
+                            'aType' => [
+                                'columnsOverrides' => [
+                                    'aField' => [
+                                        'defaultExtras' => 'richtext:rte_transform'
+                                    ]
+                                ]
+                            ]
+                        ]
+                    ]
+                ],
+            ],
+            'remove mode in columnsOverrides' => [
+                [
+                    'aTable' => [
+                        'types' => [
+                            'aType' => [
+                                'columnsOverrides' => [
+                                    'aField' => [
+                                        'defaultExtras' => 'richtext:rte_transform[mode=ts_css]'
+                                    ]
+                                ]
+                            ]
+                        ]
+                    ]
+                ],
+                [
+                    'aTable' => [
+                        'types' => [
+                            'aType' => [
+                                'columnsOverrides' => [
+                                    'aField' => [
+                                        'defaultExtras' => 'richtext:rte_transform'
+                                    ]
+                                ]
+                            ]
+                        ]
+                    ]
+                ],
+            ],
+            'remove flag and mode in columnsOverrides' => [
+                [
+                    'aTable' => [
+                        'types' => [
+                            'aType' => [
+                                'columnsOverrides' => [
+                                    'aField' => [
+                                        'defaultExtras' => 'richtext:rte_transform[flag=rte_enabled|mode=ts_css]'
+                                    ]
+                                ]
+                            ]
+                        ]
+                    ]
+                ],
+                [
+                    'aTable' => [
+                        'types' => [
+                            'aType' => [
+                                'columnsOverrides' => [
+                                    'aField' => [
+                                        'defaultExtras' => 'richtext:rte_transform'
+                                    ]
+                                ]
+                            ]
+                        ]
+                    ]
+                ],
+            ],
+            'remove flag and mode in columnsOverrides with array notation' => [
+                [
+                    'aTable' => [
+                        'types' => [
+                            'aType' => [
+                                'columnsOverrides' => [
+                                    'aField' => [
+                                        'defaultExtras' => 'richtext[]:rte_transform[flag=rte_enabled|mode=ts_css]'
+                                    ]
+                                ]
+                            ]
+                        ]
+                    ]
+                ],
+                [
+                    'aTable' => [
+                        'types' => [
+                            'aType' => [
+                                'columnsOverrides' => [
+                                    'aField' => [
+                                        'defaultExtras' => 'richtext[]:rte_transform'
+                                    ]
+                                ]
+                            ]
+                        ]
+                    ]
+                ],
+            ],
+            'remove flag and mode in columnsOverrides with array notation and index' => [
+                [
+                    'aTable' => [
+                        'types' => [
+                            'aType' => [
+                                'columnsOverrides' => [
+                                    'aField' => [
+                                        'defaultExtras' => 'richtext[*]:rte_transform[flag=rte_enabled|mode=ts_css]'
+                                    ]
+                                ]
+                            ]
+                        ]
+                    ]
+                ],
+                [
+                    'aTable' => [
+                        'types' => [
+                            'aType' => [
+                                'columnsOverrides' => [
+                                    'aField' => [
+                                        'defaultExtras' => 'richtext[*]:rte_transform'
+                                    ]
+                                ]
+                            ]
+                        ]
+                    ]
+                ],
+            ],
+            'remove flag and mode in columnsOverrides with array notation and index and option list' => [
+                [
+                    'aTable' => [
+                        'types' => [
+                            'aType' => [
+                                'columnsOverrides' => [
+                                    'aField' => [
+                                        'defaultExtras' => 'richtext[copy|cut|paste]:rte_transform[flag=rte_enabled|mode=ts_css]'
+                                    ]
+                                ]
+                            ]
+                        ]
+                    ]
+                ],
+                [
+                    'aTable' => [
+                        'types' => [
+                            'aType' => [
+                                'columnsOverrides' => [
+                                    'aField' => [
+                                        'defaultExtras' => 'richtext[copy|cut|paste]:rte_transform'
+                                    ]
+                                ]
+                            ]
+                        ]
+                    ]
+                ],
+            ],
+        ];
+    }
+
+    /**
+     * @test
+     * @dataProvider migrateRemovesRteTransformOptionsDataProvider
+     * @param array $givenConfig
+     * @param array $expectedConfig
+     */
+    public function migrateRemovesRteTransformOptions(array $givenConfig, array $expectedConfig) {
+        $subject = new TcaMigration();
+        $this->assertEquals($expectedConfig, $subject->migrate($givenConfig));
+    }
 }
index 2e2f01f..692a402 100644 (file)
@@ -502,7 +502,7 @@ $baseDefaultExtrasOfBodytext = '';
 if (!empty($GLOBALS['TCA']['tt_content']['columns']['bodytext']['defaultExtras'])) {
     $baseDefaultExtrasOfBodytext = $GLOBALS['TCA']['tt_content']['columns']['bodytext']['defaultExtras'] . ':';
 }
-$GLOBALS['TCA']['tt_content']['types']['text']['columnsOverrides']['bodytext']['defaultExtras'] = $baseDefaultExtrasOfBodytext . 'richtext:rte_transform[mode=ts_css]';
+$GLOBALS['TCA']['tt_content']['types']['text']['columnsOverrides']['bodytext']['defaultExtras'] = $baseDefaultExtrasOfBodytext . 'richtext:rte_transform';
 
 // Field arrangement for CE "textpic"
 $GLOBALS['TCA']['tt_content']['types']['textpic']['showitem'] = '
@@ -527,7 +527,7 @@ if (!is_array($GLOBALS['TCA']['tt_content']['types']['textpic']['columnsOverride
 if (!is_array($GLOBALS['TCA']['tt_content']['types']['textpic']['columnsOverrides']['bodytext'])) {
     $GLOBALS['TCA']['tt_content']['types']['textpic']['columnsOverrides']['bodytext'] = array();
 }
-$GLOBALS['TCA']['tt_content']['types']['textpic']['columnsOverrides']['bodytext']['defaultExtras'] = $baseDefaultExtrasOfBodytext . 'richtext:rte_transform[mode=ts_css]';
+$GLOBALS['TCA']['tt_content']['types']['textpic']['columnsOverrides']['bodytext']['defaultExtras'] = $baseDefaultExtrasOfBodytext . 'richtext:rte_transform';
 
 // Field arrangement for CE "image"
 $GLOBALS['TCA']['tt_content']['types']['image']['showitem'] = '
index c26f059..b075653 100644 (file)
@@ -52,7 +52,7 @@ call_user_func(function () {
                                --palette--;' . $frontendLanguageFilePrefix . 'palette.access;access,
                        --div--;' . $frontendLanguageFilePrefix . 'tabs.extended
                ',
-        'columnsOverrides' => ['bodytext' => ['defaultExtras' => 'richtext:rte_transform[mode=ts_css]']]
+        'columnsOverrides' => ['bodytext' => ['defaultExtras' => 'richtext:rte_transform']]
     ];
 
     // Add category tab when categories column exits
index 28ae799..c58ada8 100644 (file)
@@ -1296,14 +1296,10 @@ class RichTextElement extends AbstractFormElement
         $value = preg_replace('/<(\\/?)em([^b>]*>)/i', '<$1i$2', $value);
 
         if ($this->defaultExtras['rte_transform']) {
-            $parameters = BackendUtility::getSpecConfParametersFromArray($this->defaultExtras['rte_transform']['parameters']);
-            // There must be a mode set for transformation
-            if ($parameters['mode']) {
-                /** @var RteHtmlParser $parseHTML */
-                $parseHTML = GeneralUtility::makeInstance(RteHtmlParser::class);
-                $parseHTML->init($this->data['table'] . ':' . $this->data['fieldName'], $this->pidOfVersionedMotherRecord);
-                $value = $parseHTML->RTE_transform($value, $this->defaultExtras, 'rte', $this->processedRteConfiguration);
-            }
+            /** @var RteHtmlParser $parseHTML */
+            $parseHTML = GeneralUtility::makeInstance(RteHtmlParser::class);
+            $parseHTML->init($this->data['table'] . ':' . $this->data['fieldName'], $this->pidOfVersionedMotherRecord);
+            $value = $parseHTML->RTE_transform($value, $this->defaultExtras, 'rte', $this->processedRteConfiguration);
         }
         return $value;
     }