diff --git a/typo3/sysext/backend/Classes/Template/DocumentTemplate.php b/typo3/sysext/backend/Classes/Template/DocumentTemplate.php index ae2152d620d1..8088b9291c31 100644 --- a/typo3/sysext/backend/Classes/Template/DocumentTemplate.php +++ b/typo3/sysext/backend/Classes/Template/DocumentTemplate.php @@ -559,9 +559,8 @@ public function addStyleSheetDirectory($path) { $path = GeneralUtility::getFileAbsFileName($path); // Read all files in directory and sort them alphabetically - $cssFiles = GeneralUtility::getFilesInDir($path, 'css'); - foreach ($cssFiles as $cssFile) { - $this->pageRenderer->addCssFile(PathUtility::getRelativePathTo($path) . $cssFile); + foreach (GeneralUtility::getFilesInDir($path, 'css', true) as $cssFile) { + $this->pageRenderer->addCssFile($cssFile); } } diff --git a/typo3/sysext/backend/Classes/Template/ModuleTemplate.php b/typo3/sysext/backend/Classes/Template/ModuleTemplate.php index 8134550ab9de..8dc5d8a3c592 100644 --- a/typo3/sysext/backend/Classes/Template/ModuleTemplate.php +++ b/typo3/sysext/backend/Classes/Template/ModuleTemplate.php @@ -294,11 +294,11 @@ protected function loadStylesheets() if (!empty($GLOBALS['TBE_STYLES']['stylesheet2'])) { $this->pageRenderer->addCssFile($GLOBALS['TBE_STYLES']['stylesheet2']); } + // @see DocumentTemplate::addStyleSheetDirectory // Add all *.css files of the directory $path to the stylesheets foreach ($this->getRegisteredStylesheetFolders() as $folder) { // Read all files in directory and sort them alphabetically - $cssFiles = GeneralUtility::getFilesInDir($folder, 'css', true); - foreach ($cssFiles as $cssFile) { + foreach (GeneralUtility::getFilesInDir($folder, 'css', true) as $cssFile) { $this->pageRenderer->addCssFile($cssFile); } } diff --git a/typo3/sysext/core/Classes/Page/PageRenderer.php b/typo3/sysext/core/Classes/Page/PageRenderer.php index 4e1a8558db52..8661bf628eaa 100644 --- a/typo3/sysext/core/Classes/Page/PageRenderer.php +++ b/typo3/sysext/core/Classes/Page/PageRenderer.php @@ -16,7 +16,6 @@ use TYPO3\CMS\Backend\Routing\Router; use TYPO3\CMS\Backend\Routing\UriBuilder; -use TYPO3\CMS\Backend\Template\DocumentTemplate; use TYPO3\CMS\Core\Cache\CacheManager; use TYPO3\CMS\Core\Cache\Frontend\FrontendInterface; use TYPO3\CMS\Core\Core\Environment; @@ -2367,12 +2366,8 @@ protected function doConcatenateCss() ]; GeneralUtility::callUserFunction($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['cssConcatenateHandler'], $params, $this); } else { - $cssOptions = []; - if (TYPO3_MODE === 'BE') { - $cssOptions = ['baseDirectories' => GeneralUtility::makeInstance(DocumentTemplate::class)->getSkinStylesheetDirectories()]; - } - $this->cssLibs = $this->getCompressor()->concatenateCssFiles($this->cssLibs, $cssOptions); - $this->cssFiles = $this->getCompressor()->concatenateCssFiles($this->cssFiles, $cssOptions); + $this->cssLibs = $this->getCompressor()->concatenateCssFiles($this->cssLibs); + $this->cssFiles = $this->getCompressor()->concatenateCssFiles($this->cssFiles); } } } diff --git a/typo3/sysext/core/Classes/Resource/ResourceCompressor.php b/typo3/sysext/core/Classes/Resource/ResourceCompressor.php index f16cb278cc09..2d0dae8e754f 100644 --- a/typo3/sysext/core/Classes/Resource/ResourceCompressor.php +++ b/typo3/sysext/core/Classes/Resource/ResourceCompressor.php @@ -103,14 +103,10 @@ public function setRootPath($rootPath) /** * Concatenates the Stylesheet files * - * Options: - * baseDirectories If set, only include files below one of the base directories - * * @param array $cssFiles CSS files to process - * @param array $options Additional options * @return array CSS files */ - public function concatenateCssFiles(array $cssFiles, array $options = []) + public function concatenateCssFiles(array $cssFiles) { $filesToIncludeByType = ['all' => []]; foreach ($cssFiles as $key => $fileOptions) { @@ -119,45 +115,34 @@ public function concatenateCssFiles(array $cssFiles, array $options = []) continue; } $filenameFromMainDir = $this->getFilenameFromMainDir($fileOptions['file']); - // if $options['baseDirectories'] set, we only include files below these directories - if ( - !isset($options['baseDirectories']) - || $this->checkBaseDirectory( - $filenameFromMainDir, - array_merge($options['baseDirectories'], [$this->targetDirectory]) - ) - ) { - $type = isset($fileOptions['media']) ? strtolower($fileOptions['media']) : 'all'; - if (!isset($filesToIncludeByType[$type])) { - $filesToIncludeByType[$type] = []; - } - if (!empty($fileOptions['forceOnTop'])) { - array_unshift($filesToIncludeByType[$type], $filenameFromMainDir); - } else { - $filesToIncludeByType[$type][] = $filenameFromMainDir; - } - // remove the file from the incoming file array - unset($cssFiles[$key]); + $type = isset($fileOptions['media']) ? strtolower($fileOptions['media']) : 'all'; + if (!isset($filesToIncludeByType[$type])) { + $filesToIncludeByType[$type] = []; } + if (!empty($fileOptions['forceOnTop'])) { + array_unshift($filesToIncludeByType[$type], $filenameFromMainDir); + } else { + $filesToIncludeByType[$type][] = $filenameFromMainDir; + } + // remove the file from the incoming file array + unset($cssFiles[$key]); } - if (!empty($filesToIncludeByType)) { - foreach ($filesToIncludeByType as $mediaOption => $filesToInclude) { - if (empty($filesToInclude)) { - continue; - } - $targetFile = $this->createMergedCssFile($filesToInclude); - $concatenatedOptions = [ - 'file' => $targetFile, - 'rel' => 'stylesheet', - 'media' => $mediaOption, - 'compress' => true, - 'excludeFromConcatenation' => true, - 'forceOnTop' => false, - 'allWrap' => '' - ]; - // place the merged stylesheet on top of the stylesheets - $cssFiles = array_merge($cssFiles, [$targetFile => $concatenatedOptions]); + foreach ($filesToIncludeByType as $mediaOption => $filesToInclude) { + if (empty($filesToInclude)) { + continue; } + $targetFile = $this->createMergedCssFile($filesToInclude); + $concatenatedOptions = [ + 'file' => $targetFile, + 'rel' => 'stylesheet', + 'media' => $mediaOption, + 'compress' => true, + 'excludeFromConcatenation' => true, + 'forceOnTop' => false, + 'allWrap' => '' + ]; + // place the merged stylesheet on top of the stylesheets + $cssFiles = array_merge($cssFiles, [$targetFile => $concatenatedOptions]); } return $cssFiles; } @@ -447,6 +432,10 @@ protected function getFilenameFromMainDir($filename) // if the file is an absolute reference within the docRoot $absolutePath = $docRoot . '/' . $fileNameWithoutSlash; + // if it is already an absolute path to the file + if (PathUtility::isAbsolutePath($filename)) { + $absolutePath = $filename; + } // Calling is_file without @ for a path starting with '../' causes a PHP Warning when using open_basedir restriction if (@is_file($absolutePath)) { if (strpos($absolutePath, $this->rootPath) === 0) { diff --git a/typo3/sysext/core/Documentation/Changelog/master/Breaking-88758-SelectiveConcatenationOfCSSFilesInResourceCompressorRemoved.rst b/typo3/sysext/core/Documentation/Changelog/master/Breaking-88758-SelectiveConcatenationOfCSSFilesInResourceCompressorRemoved.rst new file mode 100644 index 000000000000..ab231a5a4e10 --- /dev/null +++ b/typo3/sysext/core/Documentation/Changelog/master/Breaking-88758-SelectiveConcatenationOfCSSFilesInResourceCompressorRemoved.rst @@ -0,0 +1,45 @@ +.. include:: ../../Includes.txt + +===================================================================================== +Breaking: #88758 - Selective Concatenation of CSS files in ResourceCompressor removed +===================================================================================== + +See :issue:`88758` + +Description +=========== + +ResourceCompressor, used to merge and compress CSS and JS files, has had an option to only +merge CSS files from selected folders. This was used to limit CSS files of skins for TYPO3 +Backend files. + +The functionality has been removed, as all added CSS files are now merged into one file. + +As TYPO3 Frontend and TypoScript has a much more flexible system for adding CSS files, +which should be concatenated, this change does not affect TYPO3 API of Frontend Requests. + + +Impact +====== + +Calling ResourceCompressor->concatenateCssFiles() with a second argument has no effect anymore. + +Adding CSS files manually in TYPO3 Backend via custom extensions will now automatically be merged +with the loaded CSS styles of :php:`$TBE_STYLES` skin. + + +Affected Installations +====================== + +TYPO3 installations with extensions adding third-party CSS files in the TYPO3 Backend, +or extensions using ResourceCompressor directly. + + +Migration +========= + +None, as it is considered to be useful to have one larger CSS file for TYPO3 Backend. + +If necessary, add a CSS file manually via PageRenderer API which should be excluded from Concatenation. + +.. index:: PHP-API, FullyScanned \ No newline at end of file diff --git a/typo3/sysext/install/Configuration/ExtensionScanner/Php/MethodArgumentDroppedMatcher.php b/typo3/sysext/install/Configuration/ExtensionScanner/Php/MethodArgumentDroppedMatcher.php index 77aa832521ed..a690b70eab1b 100644 --- a/typo3/sysext/install/Configuration/ExtensionScanner/Php/MethodArgumentDroppedMatcher.php +++ b/typo3/sysext/install/Configuration/ExtensionScanner/Php/MethodArgumentDroppedMatcher.php @@ -241,4 +241,10 @@ 'Breaking-88741-CHashCalculationInIndexedSearchRemoved.rst', ], ], + 'TYPO3\CMS\Core\Resource\ResourceCompressor->concatenateCssFiles' => [ + 'maximumNumberOfArguments' => 1, + 'restFiles' => [ + 'Breaking-88758-SelectiveConcatenationOfCSSFilesInResourceCompressorRemoved.rst', + ], + ], ];