From 47b7c008769248ae47c976cd1693aea405df61d3 Mon Sep 17 00:00:00 2001
From: Oliver Bartsch <bo@cedev.de>
Date: Tue, 24 Aug 2021 18:03:05 +0200
Subject: [PATCH] [TASK] Reduce RTE options for sys_news content

System news records (sys_news) contain a `content`
field, which features a richtext editor. Previously using
the default configuration, having most of the available
options enabled.

Since system news are only displayed on the login
screen and are only intended for simple information,
most of the options are not relevant. Additionally,
some of those options did not work at all, due to
the missing frontend context (see e.g. #67556).

To ease the use for administrators, a simplified
RTE configuration is now used for the `content`
field of sys_news records.

In case administrators need additional options,
this can as usual still be achieved by overriding
the corresponding TCA configuration.

Resolves: #94980
Releases: master
Change-Id: Ib8825344b453a3d19c5cbcd96844be3c47408f9a
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/70742
Tested-by: core-ci <typo3@b13.com>
Tested-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Oliver Bartsch <bo@cedev.de>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Oliver Bartsch <bo@cedev.de>
---
 .../core/Configuration/RTE/SysNews.yaml       | 28 +++++++++++++++++++
 .../core/Configuration/TCA/sys_news.php       |  1 +
 typo3/sysext/core/ext_localconf.php           |  5 ++++
 3 files changed, 34 insertions(+)
 create mode 100644 typo3/sysext/core/Configuration/RTE/SysNews.yaml

diff --git a/typo3/sysext/core/Configuration/RTE/SysNews.yaml b/typo3/sysext/core/Configuration/RTE/SysNews.yaml
new file mode 100644
index 000000000000..2169bf640139
--- /dev/null
+++ b/typo3/sysext/core/Configuration/RTE/SysNews.yaml
@@ -0,0 +1,28 @@
+# @internal Only to be used for sys_news
+
+imports:
+  - { resource: "EXT:rte_ckeditor/Configuration/RTE/Processing.yaml" }
+  - { resource: "EXT:rte_ckeditor/Configuration/RTE/Editor/Base.yaml" }
+  - { resource: "EXT:rte_ckeditor/Configuration/RTE/Editor/Plugins.yaml" }
+
+editor:
+  config:
+
+    toolbarGroups:
+      - { name: basicstyles, groups: [ basicstyles ] }
+      - { name: paragraph, groups: [ list, indent, blocks, align ] }
+      - { name: links, groups: [ links ] }
+      - { name: clipboard, groups: [clipboard, undo] }
+      - { name: document, groups: [ mode ] }
+
+    removeButtons:
+      - Anchor
+      - Style
+      - Underline
+      - Strike
+
+    removePlugins:
+      - image
+
+    extraPlugins:
+      - autolink
diff --git a/typo3/sysext/core/Configuration/TCA/sys_news.php b/typo3/sysext/core/Configuration/TCA/sys_news.php
index f3dc297f5681..7b2bb79189fd 100644
--- a/typo3/sysext/core/Configuration/TCA/sys_news.php
+++ b/typo3/sysext/core/Configuration/TCA/sys_news.php
@@ -74,6 +74,7 @@ return [
                 'cols' => 48,
                 'rows' => 5,
                 'enableRichtext' => true,
+                'richtextConfiguration' => 'sys_news'
             ],
         ],
         'crdate' => [
diff --git a/typo3/sysext/core/ext_localconf.php b/typo3/sysext/core/ext_localconf.php
index ee3ebb76e3b6..0496d93a3a6e 100644
--- a/typo3/sysext/core/ext_localconf.php
+++ b/typo3/sysext/core/ext_localconf.php
@@ -71,3 +71,8 @@ unset($metaTagManagerRegistry);
 \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTypoScriptSetup(
     'config.pageTitleProviders.record.provider = TYPO3\CMS\Core\PageTitle\RecordPageTitleProvider'
 );
+
+// Register preset for sys_news
+if (empty($GLOBALS['TYPO3_CONF_VARS']['RTE']['Presets']['sys_news'])) {
+    $GLOBALS['TYPO3_CONF_VARS']['RTE']['Presets']['sys_news'] = 'EXT:core/Configuration/RTE/SysNews.yaml';
+}
-- 
GitLab