[TASK] Move preparation of non-cacheable headerdata into TSFE 02/62302/4
authorBenni Mack <benni@typo3.org>
Tue, 12 Nov 2019 12:08:57 +0000 (13:08 +0100)
committerGeorg Ringer <georg.ringer@gmail.com>
Tue, 12 Nov 2019 13:47:03 +0000 (14:47 +0100)
In order to centralize USER_INT ("non-cacheables") into TSFE logic,
some functionality is moved into TSFE regarding headerData,
JS and CSS inclusions.

Resolves: #89651
Releases: master
Change-Id: Ib0f6daa2306f6cba90f27db6baff5bae38403842
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/62302
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Daniel Gorges <daniel.gorges@b13.com>
Tested-by: Oliver Bartsch <bo@cedev.de>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
Reviewed-by: Daniel Gorges <daniel.gorges@b13.com>
Reviewed-by: Oliver Bartsch <bo@cedev.de>
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
typo3/sysext/frontend/Classes/Controller/TypoScriptFrontendController.php
typo3/sysext/frontend/Classes/Http/RequestHandler.php

index 37a9c95..2e0cedc 100644 (file)
@@ -3044,21 +3044,43 @@ class TypoScriptFrontendController implements LoggerAwareInterface
     }
 
     /**
-     * Loads the JavaScript code for INTincScript
+     * Loads the JavaScript/CSS code for INTincScript, if there are non-cacheable content objects
+     * it prepares the placeholders, otherwise populates options directly.
+     *
+     * @internal this method should be renamed as it does not only handle JS, but all additional header data
      */
     public function INTincScript_loadJSCode()
     {
-        // Add javascript
-        $jsCode = trim($this->JSCode);
-        $additionalJavaScript = is_array($this->additionalJavaScript)
-            ? implode(LF, $this->additionalJavaScript)
-            : $this->additionalJavaScript;
-        $additionalJavaScript = trim($additionalJavaScript);
-        if ($jsCode !== '' || $additionalJavaScript !== '') {
-            $doctype = $controller->config['config']['doctype'] ?? 'html5';
-            $scriptAttribute = $doctype === 'html5' ? '' : ' type="text/javascript"';
-
-            $this->additionalHeaderData['JSCode'] = '
+        // Prepare code and placeholders for additional header and footer files (and make sure that this isn't called twice)
+        if ($this->isINTincScript() && !isset($this->config['INTincScript_ext'])) {
+            // Storing the JSCode vars...
+            $this->additionalHeaderData['JSCode'] = $this->JSCode;
+            $this->config['INTincScript_ext']['divKey'] = $this->uniqueHash();
+            // Storing the header-data array
+            $this->config['INTincScript_ext']['additionalHeaderData'] = $this->additionalHeaderData;
+            // Storing the footer-data array
+            $this->config['INTincScript_ext']['additionalFooterData'] = $this->additionalFooterData;
+            // Storing the JS-data array
+            $this->config['INTincScript_ext']['additionalJavaScript'] = $this->additionalJavaScript;
+            // Storing the Style-data array
+            $this->config['INTincScript_ext']['additionalCSS'] = $this->additionalCSS;
+            // Clearing the array
+            $this->additionalHeaderData = ['<!--HD_' . $this->config['INTincScript_ext']['divKey'] . '-->'];
+            // Clearing the array
+            $this->additionalFooterData = ['<!--FD_' . $this->config['INTincScript_ext']['divKey'] . '-->'];
+            $this->divSection .= '<!--TDS_' . $this->config['INTincScript_ext']['divKey'] . '-->';
+        } else {
+            // Add javascript
+            $jsCode = trim($this->JSCode);
+            $additionalJavaScript = is_array($this->additionalJavaScript)
+                ? implode(LF, $this->additionalJavaScript)
+                : $this->additionalJavaScript;
+            $additionalJavaScript = trim($additionalJavaScript);
+            if ($jsCode !== '' || $additionalJavaScript !== '') {
+                $doctype = $this->config['config']['doctype'] ?? 'html5';
+                $scriptAttribute = $doctype === 'html5' ? '' : ' type="text/javascript"';
+
+                $this->additionalHeaderData['JSCode'] = '
 <script' . $scriptAttribute . '>
        /*<![CDATA[*/
 <!--
@@ -3067,15 +3089,16 @@ class TypoScriptFrontendController implements LoggerAwareInterface
 // -->
        /*]]>*/
 </script>';
-        }
-        // Add CSS
-        $additionalCss = is_array($this->additionalCSS) ? implode(LF, $this->additionalCSS) : $this->additionalCSS;
-        $additionalCss = trim($additionalCss);
-        if ($additionalCss !== '') {
-            $this->additionalHeaderData['_CSS'] = '
+            }
+            // Add CSS
+            $additionalCss = is_array($this->additionalCSS) ? implode(LF, $this->additionalCSS) : $this->additionalCSS;
+            $additionalCss = trim($additionalCss);
+            if ($additionalCss !== '') {
+                $this->additionalHeaderData['_CSS'] = '
 <style type="text/css">
 ' . $additionalCss . '
 </style>';
+            }
         }
     }
 
index b9776be..997b456 100644 (file)
@@ -673,26 +673,8 @@ class RequestHandler implements RequestHandlerInterface
         );
 
         unset($controller->additionalHeaderData['JSCode']);
-        if (isset($controller->config['INTincScript']) && is_array($controller->config['INTincScript'])) {
-            $controller->additionalHeaderData['JSCode'] = $controller->JSCode;
-            // Storing the JSCode vars...
-            $controller->config['INTincScript_ext']['divKey'] = $controller->uniqueHash();
-            $controller->config['INTincScript_ext']['additionalHeaderData'] = $controller->additionalHeaderData;
-            // Storing the header-data array
-            $controller->config['INTincScript_ext']['additionalFooterData'] = $controller->additionalFooterData;
-            // Storing the footer-data array
-            $controller->config['INTincScript_ext']['additionalJavaScript'] = $controller->additionalJavaScript;
-            // Storing the JS-data array
-            $controller->config['INTincScript_ext']['additionalCSS'] = $controller->additionalCSS;
-            // Storing the Style-data array
-            $controller->additionalHeaderData = ['<!--HD_' . $controller->config['INTincScript_ext']['divKey'] . '-->'];
-            // Clearing the array
-            $controller->additionalFooterData = ['<!--FD_' . $controller->config['INTincScript_ext']['divKey'] . '-->'];
-            // Clearing the array
-            $controller->divSection .= '<!--TDS_' . $controller->config['INTincScript_ext']['divKey'] . '-->';
-        } else {
-            $controller->INTincScript_loadJSCode();
-        }
+        $controller->INTincScript_loadJSCode();
+
         $scriptJsCode = '';
 
         if ($controller->spamProtectEmailAddresses && $controller->spamProtectEmailAddresses !== 'ascii') {