[FEATURE] Exclude Page CSS from Concatenation 98/33098/5
authorSusanne Moog <typo3@susannemoog.de>
Mon, 20 Jul 2015 18:51:57 +0000 (20:51 +0200)
committerSusanne Moog <typo3@susannemoog.de>
Fri, 7 Aug 2015 11:41:05 +0000 (13:41 +0200)
CSS added via _CSS_PAGE_STYLE is no longer included in
the concatenated css files. It can be written in an external
file or as inline block (depending on inlineStyle2TempFile).

Additionally the config.compressCss setting is now taken into
account.

Resolves: #61993
Releases: master

Change-Id: I0c9cc6ababbd5695b0dab26e7d421f28b5f73bb0
Reviewed-on: http://review.typo3.org/33098
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Susanne Moog <typo3@susannemoog.de>
Tested-by: Susanne Moog <typo3@susannemoog.de>
typo3/sysext/core/Documentation/Changelog/master/Feature-61993-CssPageStyleNowPageSpecific.rst [new file with mode: 0644]
typo3/sysext/frontend/Classes/Page/PageGenerator.php

diff --git a/typo3/sysext/core/Documentation/Changelog/master/Feature-61993-CssPageStyleNowPageSpecific.rst b/typo3/sysext/core/Documentation/Changelog/master/Feature-61993-CssPageStyleNowPageSpecific.rst
new file mode 100644 (file)
index 0000000..5463fbf
--- /dev/null
@@ -0,0 +1,16 @@
+===========================================================================
+Feature: #61993 - _CSS_PAGE_STYLE is now only included on the affected page
+===========================================================================
+
+Description
+===========
+
+CSS set via the TypoScript property _CSS_PAGE_STYLE was concatenated and compressed with the non-page-specific CSS and
+therefore loaded on pages it did not affect at all.
+
+Impact
+======
+
+The behaviour from now on is that _CSS_PAGE_STYLE is included only on the affected page. Depending on your configuration
+it will be written in an external file and included on the page or directly added as inline CSS block. Compression for
+page specific CSS also depends on the global config.compressCss setting.
index 8a266d0..037d8f4 100644 (file)
@@ -405,7 +405,7 @@ class PageGenerator {
                }
                // Including CSS files
                if (is_array($tsfe->tmpl->setup['plugin.'])) {
-                       $temp_styleLines = array();
+                       $stylesFromPlugins = '';
                        foreach ($tsfe->tmpl->setup['plugin.'] as $key => $iCSScode) {
                                if (is_array($iCSScode)) {
                                        if ($iCSScode['_CSS_DEFAULT_STYLE'] && empty($tsfe->config['config']['removeDefaultCss'])) {
@@ -414,23 +414,20 @@ class PageGenerator {
                                                } else {
                                                        $cssDefaultStyle = $iCSScode['_CSS_DEFAULT_STYLE'];
                                                }
-                                               $temp_styleLines[] = '/* default styles for extension "' . substr($key, 0, -1) . '" */' . LF . $cssDefaultStyle;
+                                               $stylesFromPlugins .= '/* default styles for extension "' . substr($key, 0, -1) . '" */' . LF . $cssDefaultStyle . LF;
                                        }
                                        if ($iCSScode['_CSS_PAGE_STYLE'] && empty($tsfe->config['config']['removePageCss'])) {
                                                $cssPageStyle = implode(LF, $iCSScode['_CSS_PAGE_STYLE']);
                                                if (isset($iCSScode['_CSS_PAGE_STYLE.'])) {
                                                        $cssPageStyle = $tsfe->cObj->stdWrap($cssPageStyle, $iCSScode['_CSS_PAGE_STYLE.']);
                                                }
-                                               $temp_styleLines[] = '/* specific page styles for extension "' . substr($key, 0, -1) . '" */' . LF . $cssPageStyle;
+                                               $cssPageStyle = '/* specific page styles for extension "' . substr($key, 0, -1) . '" */' . LF . $cssPageStyle;
+                                               self::addCssToPageRenderer($cssPageStyle, TRUE);
                                        }
                                }
                        }
-                       if (!empty($temp_styleLines)) {
-                               if ($tsfe->config['config']['inlineStyle2TempFile']) {
-                                       $pageRenderer->addCssFile(self::inline2TempFile(implode(LF, $temp_styleLines), 'css'));
-                               } else {
-                                       $pageRenderer->addCssInlineBlock('TSFEinlineStyle', implode(LF, $temp_styleLines));
-                               }
+                       if (!empty($stylesFromPlugins)) {
+                               self::addCssToPageRenderer($stylesFromPlugins);
                        }
                }
                if ($tsfe->pSetup['stylesheet']) {
@@ -542,11 +539,7 @@ class PageGenerator {
                $style .= trim($tsfe->pSetup['CSS_inlineStyle']);
                $style .= $tsfe->cObj->cObjGet($tsfe->pSetup['cssInline.'], 'cssInline.');
                if (trim($style)) {
-                       if ($tsfe->config['config']['inlineStyle2TempFile']) {
-                               $pageRenderer->addCssFile(self::inline2TempFile($style, 'css'));
-                       } else {
-                               $pageRenderer->addCssInlineBlock('additionalTSFEInlineStyle', $style);
-                       }
+                       self::addCssToPageRenderer($style, TRUE, 'additionalTSFEInlineStyle');
                }
                // Javascript Libraries
                if (is_array($tsfe->pSetup['javascriptLibs.'])) {
@@ -1200,4 +1193,28 @@ class PageGenerator {
        static protected function getPageRenderer() {
                return GeneralUtility::makeInstance(PageRenderer::class);
        }
+
+       /**
+        * Adds inline CSS code, by respecting the inlineStyle2TempFile option
+        *
+        * @param string $cssStyles the inline CSS styling
+        * @param bool $excludeFromConcatenation option to see if it should be conctatenated
+        * @param string $inlineBlockName the block name to add it
+        */
+       static protected function addCssToPageRenderer($cssStyles, $excludeFromConcatenation = FALSE, $inlineBlockName = 'TSFEinlineStyle') {
+               if (empty($GLOBALS['TSFE']->config['config']['inlineStyle2TempFile'])) {
+                       self::getPageRenderer()->addCssInlineBlock($inlineBlockName, $cssStyles, !empty($GLOBALS['TSFE']->config['config']['compressCss']));
+               } else {
+                       self::getPageRenderer()->addCssFile(
+                               self::inline2TempFile($cssStyles, 'css'),
+                               'stylesheet',
+                               'all',
+                               '',
+                               (bool)$GLOBALS['TSFE']->config['config']['compressCss'],
+                               FALSE,
+                               '',
+                               $excludeFromConcatenation
+                       );
+               }
+       }
 }