From a253022822f5ac6295801951ff13746cea87bd84 Mon Sep 17 00:00:00 2001 From: Benni Mack <benni@typo3.org> Date: Wed, 20 Jan 2016 23:03:46 +0100 Subject: [PATCH] [!!!][TASK] Remove RTE "modes" option in TCA MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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> --- .../core/Classes/DataHandling/DataHandler.php | 16 +- .../core/Classes/Migrations/TcaMigration.php | 67 ++++ .../core/Configuration/TCA/sys_news.php | 2 +- ...eprecation-72856-RemovedRTEModesOption.rst | 22 ++ .../Unit/Migrations/TcaMigrationTest.php | 358 ++++++++++++++++++ .../TCA/Overrides/tt_content.php | 4 +- .../TCA/Overrides/tt_content.php | 2 +- .../Classes/Form/Element/RichTextElement.php | 12 +- 8 files changed, 461 insertions(+), 22 deletions(-) create mode 100644 typo3/sysext/core/Documentation/Changelog/master/Deprecation-72856-RemovedRTEModesOption.rst diff --git a/typo3/sysext/core/Classes/DataHandling/DataHandler.php b/typo3/sysext/core/Classes/DataHandling/DataHandler.php index 485269c97307..260fca1843bb 100644 --- a/typo3/sysext/core/Classes/DataHandling/DataHandler.php +++ b/typo3/sysext/core/Classes/DataHandling/DataHandler.php @@ -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; } diff --git a/typo3/sysext/core/Classes/Migrations/TcaMigration.php b/typo3/sysext/core/Classes/Migrations/TcaMigration.php index 86a0b04cb05d..24016185edb6 100644 --- a/typo3/sysext/core/Classes/Migrations/TcaMigration.php +++ b/typo3/sysext/core/Classes/Migrations/TcaMigration.php @@ -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; + } } diff --git a/typo3/sysext/core/Configuration/TCA/sys_news.php b/typo3/sysext/core/Configuration/TCA/sys_news.php index 6fa930f48164..23a55f8b9f41 100644 --- a/typo3/sysext/core/Configuration/TCA/sys_news.php +++ b/typo3/sysext/core/Configuration/TCA/sys_news.php @@ -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 index 000000000000..e059febfdc69 --- /dev/null +++ b/typo3/sysext/core/Documentation/Changelog/master/Deprecation-72856-RemovedRTEModesOption.rst @@ -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 diff --git a/typo3/sysext/core/Tests/Unit/Migrations/TcaMigrationTest.php b/typo3/sysext/core/Tests/Unit/Migrations/TcaMigrationTest.php index 2d97eb3b203c..f3fab06664ab 100644 --- a/typo3/sysext/core/Tests/Unit/Migrations/TcaMigrationTest.php +++ b/typo3/sysext/core/Tests/Unit/Migrations/TcaMigrationTest.php @@ -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)); + } } diff --git a/typo3/sysext/css_styled_content/Configuration/TCA/Overrides/tt_content.php b/typo3/sysext/css_styled_content/Configuration/TCA/Overrides/tt_content.php index 2e2f01f7bd87..692a402c735c 100644 --- a/typo3/sysext/css_styled_content/Configuration/TCA/Overrides/tt_content.php +++ b/typo3/sysext/css_styled_content/Configuration/TCA/Overrides/tt_content.php @@ -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'] = ' diff --git a/typo3/sysext/fluid_styled_content/Configuration/TCA/Overrides/tt_content.php b/typo3/sysext/fluid_styled_content/Configuration/TCA/Overrides/tt_content.php index c26f059030c9..b075653124f2 100644 --- a/typo3/sysext/fluid_styled_content/Configuration/TCA/Overrides/tt_content.php +++ b/typo3/sysext/fluid_styled_content/Configuration/TCA/Overrides/tt_content.php @@ -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 diff --git a/typo3/sysext/rtehtmlarea/Classes/Form/Element/RichTextElement.php b/typo3/sysext/rtehtmlarea/Classes/Form/Element/RichTextElement.php index 28ae79909105..c58ada897711 100644 --- a/typo3/sysext/rtehtmlarea/Classes/Form/Element/RichTextElement.php +++ b/typo3/sysext/rtehtmlarea/Classes/Form/Element/RichTextElement.php @@ -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; } -- GitLab