From 0d4e2457ddd51d8690da79b70e98fe6f75707028 Mon Sep 17 00:00:00 2001
From: Markus Klein <markus.klein@typo3.org>
Date: Tue, 17 Nov 2015 19:53:09 +0100
Subject: [PATCH] [TASK] CSC: Do not show pageTS template if it's included by
 default

If the extension css_styled_content is configured to include the
pageTS by default, there is no need to show the template in the
page resources.

Resolves: #71639
Releases: master
Change-Id: I3816e8030ea01c6239dcdc0f7a178b64989c6633
Reviewed-on: https://review.typo3.org/44762
Reviewed-by: Andreas Fernandez <typo3@scripting-base.de>
Tested-by: Andreas Fernandez <typo3@scripting-base.de>
Reviewed-by: Josef Glatz <josef.glatz@typo3.org>
Tested-by: Josef Glatz <josef.glatz@typo3.org>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Markus Klein <markus.klein@typo3.org>
Tested-by: Markus Klein <markus.klein@typo3.org>
---
 .../Classes/Hooks/TcaCacheClearing.php        | 34 +++++++++++++++++++
 .../Configuration/TCA/Overrides/pages.php     | 19 ++++++++---
 .../css_styled_content/ext_localconf.php      | 24 +++++++++++--
 .../Classes/Hooks/TcaCacheClearing.php        | 34 +++++++++++++++++++
 .../fluid_styled_content/ext_localconf.php    |  8 +++++
 5 files changed, 111 insertions(+), 8 deletions(-)
 create mode 100644 typo3/sysext/css_styled_content/Classes/Hooks/TcaCacheClearing.php
 create mode 100644 typo3/sysext/fluid_styled_content/Classes/Hooks/TcaCacheClearing.php

diff --git a/typo3/sysext/css_styled_content/Classes/Hooks/TcaCacheClearing.php b/typo3/sysext/css_styled_content/Classes/Hooks/TcaCacheClearing.php
new file mode 100644
index 000000000000..b7ea4c28da5c
--- /dev/null
+++ b/typo3/sysext/css_styled_content/Classes/Hooks/TcaCacheClearing.php
@@ -0,0 +1,34 @@
+<?php
+namespace TYPO3\CMS\CssStyledContent\Hooks;
+
+/*
+ * 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\Core\Cache\CacheManager;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
+
+/**
+ * Utility to clear the TCA cache
+ */
+class TcaCacheClearing
+{
+    /**
+     * Flush the cache_core cache to remove cached TCA
+     *
+     * @return void
+     */
+    public static function clearTcaCache()
+    {
+        $cacheManager = GeneralUtility::makeInstance(CacheManager::class);
+        $cacheManager->getCache('cache_core')->flush();
+    }
+}
diff --git a/typo3/sysext/css_styled_content/Configuration/TCA/Overrides/pages.php b/typo3/sysext/css_styled_content/Configuration/TCA/Overrides/pages.php
index d7aeda7c06e6..739e7fdf941b 100644
--- a/typo3/sysext/css_styled_content/Configuration/TCA/Overrides/pages.php
+++ b/typo3/sysext/css_styled_content/Configuration/TCA/Overrides/pages.php
@@ -1,9 +1,18 @@
 <?php
 defined('TYPO3_MODE') or die();
 
-// Add pageTSconfig
-\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::registerPageTSConfigFile(
-    'css_styled_content',
-    'Configuration/PageTSconfig/NewContentElementWizard.ts',
-    'CSS-based Content Elements'
+call_user_func(
+    function ($extKey) {
+        $extConf = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf'][$extKey]);
+
+        if (isset($extConf['loadContentElementWizardTsConfig']) && (int)$extConf['loadContentElementWizardTsConfig'] === 0) {
+            // Add pageTSconfig
+            \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::registerPageTSConfigFile(
+                $extKey,
+                'Configuration/PageTSconfig/NewContentElementWizard.ts',
+                'CSS-based Content Elements'
+            );
+        }
+    },
+    'css_styled_content'
 );
diff --git a/typo3/sysext/css_styled_content/ext_localconf.php b/typo3/sysext/css_styled_content/ext_localconf.php
index 162abb586d16..4cdbbb626182 100644
--- a/typo3/sysext/css_styled_content/ext_localconf.php
+++ b/typo3/sysext/css_styled_content/ext_localconf.php
@@ -25,7 +25,25 @@ $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/class.tx_cms_layout.php'][
 $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/class.tx_cms_layout.php']['tt_content_drawItem']['text'] =
     \TYPO3\CMS\CssStyledContent\Hooks\PageLayoutView\TextPreviewRenderer::class;
 
-if (!isset($extConf['loadContentElementWizardTsConfig']) || (int)$extConf['loadContentElementWizardTsConfig'] === 1) {
-    // Include new content elements to modWizards
-    \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addPageTSConfig('<INCLUDE_TYPOSCRIPT: source="FILE:EXT:css_styled_content/Configuration/PageTSconfig/NewContentElementWizard.ts">');
+if (TYPO3_MODE === 'BE') {
+    call_user_func(
+        function ($extKey) {
+            // Get the extension configuration
+            $extConf = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf'][$extKey]);
+
+            if (!isset($extConf['loadContentElementWizardTsConfig']) || (int)$extConf['loadContentElementWizardTsConfig'] === 1) {
+                // Include new content elements to modWizards
+                \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addPageTSConfig('<INCLUDE_TYPOSCRIPT: source="FILE:EXT:css_styled_content/Configuration/PageTSconfig/NewContentElementWizard.ts">');
+            }
+
+            $dispatcher = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\SignalSlot\Dispatcher::class);
+            $dispatcher->connect(
+                \TYPO3\CMS\Extensionmanager\Controller\ConfigurationController::class,
+                'afterExtensionConfigurationWrite',
+                \TYPO3\CMS\CssStyledContent\Hooks\TcaCacheClearing::class,
+                'clearTcaCache'
+            );
+        },
+        $_EXTKEY
+    );
 }
diff --git a/typo3/sysext/fluid_styled_content/Classes/Hooks/TcaCacheClearing.php b/typo3/sysext/fluid_styled_content/Classes/Hooks/TcaCacheClearing.php
new file mode 100644
index 000000000000..38aaeffea153
--- /dev/null
+++ b/typo3/sysext/fluid_styled_content/Classes/Hooks/TcaCacheClearing.php
@@ -0,0 +1,34 @@
+<?php
+namespace TYPO3\CMS\FluidStyledContent\Hooks;
+
+/*
+ * 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\Core\Cache\CacheManager;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
+
+/**
+ * Utility to clear the TCA cache
+ */
+class TcaCacheClearing
+{
+    /**
+     * Flush the cache_core cache to remove cached TCA
+     *
+     * @return void
+     */
+    public function clearTcaCache()
+    {
+        $cacheManager = GeneralUtility::makeInstance(CacheManager::class);
+        $cacheManager->getCache('cache_core')->flush();
+    }
+}
diff --git a/typo3/sysext/fluid_styled_content/ext_localconf.php b/typo3/sysext/fluid_styled_content/ext_localconf.php
index 0870d3ded628..272b8b7e1608 100644
--- a/typo3/sysext/fluid_styled_content/ext_localconf.php
+++ b/typo3/sysext/fluid_styled_content/ext_localconf.php
@@ -17,6 +17,14 @@ if (TYPO3_MODE === 'BE') {
                 // Include new content elements to modWizards
                 \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addPageTSConfig('<INCLUDE_TYPOSCRIPT: source="FILE:EXT:fluid_styled_content/Configuration/PageTSconfig/NewContentElementWizard.ts">');
             }
+
+            $dispatcher = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\SignalSlot\Dispatcher::class);
+            $dispatcher->connect(
+                \TYPO3\CMS\Extensionmanager\Controller\ConfigurationController::class,
+                'afterExtensionConfigurationWrite',
+                \TYPO3\CMS\FluidStyledContent\Hooks\TcaCacheClearing::class,
+                'clearTcaCache'
+            );
         },
         $_EXTKEY
     );
-- 
GitLab