Skip to content

Commit 73b0b65

Browse files
author
Sven Wappler
committed
v12 compatibility
1 parent 6ff98a6 commit 73b0b65

File tree

4 files changed

+89
-13
lines changed

4 files changed

+89
-13
lines changed

Classes/Hooks/RenderPreProcessorHook.php

+12-3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
use ScssPhp\ScssPhp\Exception\SassException;
2626
use ScssPhp\ScssPhp\OutputStyle;
2727
use TYPO3\CMS\Core\Cache\Exception\NoSuchCacheException;
28+
use TYPO3\CMS\Core\Http\ApplicationType;
2829
use TYPO3\CMS\Core\Page\PageRenderer;
2930
use TYPO3\CMS\Core\Resource\Exception\FileDoesNotExistException;
3031
use TYPO3\CMS\Core\Utility\GeneralUtility;
@@ -60,12 +61,19 @@ class RenderPreProcessorHook
6061
*/
6162
public function renderPreProcessorProc(array &$params, PageRenderer $pagerenderer): void
6263
{
64+
65+
if ($GLOBALS['TYPO3_REQUEST'] == null ||
66+
!ApplicationType::fromRequest($GLOBALS['TYPO3_REQUEST'])->isFrontend()
67+
) {
68+
return;
69+
}
70+
6371
if (!\is_array($params['cssFiles'])) {
6472
return;
6573
}
6674

6775
$setup = $GLOBALS['TSFE']->tmpl->setup;
68-
if (\is_array($setup['plugin.']['tx_wsscss.']['variables.'])) {
76+
if (\is_array($setup['plugin.']['tx_wsscss.']['variables.'] ?? null)) {
6977

7078
$variables = $setup['plugin.']['tx_wsscss.']['variables.'];
7179

@@ -108,7 +116,7 @@ public function renderPreProcessorProc(array &$params, PageRenderer $pagerendere
108116
}
109117

110118
if ($file === $keyValue) {
111-
$subConf = $GLOBALS['TSFE']->pSetup['includeCSS.'][$key.'.'] ?? [];
119+
$subConf = $GLOBALS['TSFE']->pSetup['includeCSS.'][$key . '.'] ?? [];
112120

113121
$outputFilePath = $subConf['outputfile'] ?? null;
114122
$useSourceMap = $this->parseBooleanSetting($subConf['sourceMap'] ?? false, false);
@@ -143,7 +151,8 @@ public function renderPreProcessorProc(array &$params, PageRenderer $pagerendere
143151
$params['cssFiles'] = $cssFiles;
144152
}
145153

146-
private function parseBooleanSetting(string $value, bool $defaultValue) : bool {
154+
private function parseBooleanSetting(string $value, bool $defaultValue): bool
155+
{
147156
if (trim($value) === 'true' || trim($value) === '1') {
148157
return true;
149158
}

Classes/ViewHelpers/Asset/ScssViewHelper.php

+66-3
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,80 @@
66

77
use ScssPhp\ScssPhp\Exception\SassException;
88
use TYPO3\CMS\Core\Cache\Exception\NoSuchCacheException;
9+
use TYPO3\CMS\Core\Page\AssetCollector;
910
use TYPO3\CMS\Core\Resource\Exception\FileDoesNotExistException;
10-
use TYPO3\CMS\Fluid\ViewHelpers\Asset\CssViewHelper;
11+
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper;
12+
use TYPO3Fluid\Fluid\Core\ViewHelper\TagBuilder;
1113
use WapplerSystems\WsScss\Compiler;
1214

13-
class ScssViewHelper extends CssViewHelper
15+
class ScssViewHelper extends AbstractTagBasedViewHelper
1416
{
17+
/**
18+
* This VH does not produce direct output, thus does not need to be wrapped in an escaping node
19+
*
20+
* @var bool
21+
*/
22+
protected $escapeOutput = false;
23+
24+
/**
25+
* Rendered children string is passed as CSS code,
26+
* there is no point in HTML encoding anything from that.
27+
*
28+
* @var bool
29+
*/
30+
protected $escapeChildren = true;
31+
32+
protected AssetCollector $assetCollector;
33+
34+
public function injectAssetCollector(AssetCollector $assetCollector): void
35+
{
36+
$this->assetCollector = $assetCollector;
37+
}
38+
39+
public function initialize(): void
40+
{
41+
// Add a tag builder, that does not html encode values, because rendering with encoding happens in AssetRenderer
42+
$this->setTagBuilder(
43+
new class () extends TagBuilder {
44+
public function addAttribute($attributeName, $attributeValue, $escapeSpecialCharacters = false): void
45+
{
46+
parent::addAttribute($attributeName, $attributeValue, false);
47+
}
48+
}
49+
);
50+
parent::initialize();
51+
}
1552

1653
public function initializeArguments(): void
1754
{
1855
parent::initializeArguments();
19-
56+
$this->registerUniversalTagAttributes();
57+
$this->registerTagAttribute('as', 'string', 'Define the type of content being loaded (For rel="preload" or rel="prefetch" only).', false);
58+
$this->registerTagAttribute('crossorigin', 'string', 'Define how to handle crossorigin requests.', false);
59+
$this->registerTagAttribute('disabled', 'bool', 'Define whether or not the described stylesheet should be loaded and applied to the document.', false);
60+
$this->registerTagAttribute('href', 'string', 'Define the URL of the resource (absolute or relative).', false);
61+
$this->registerTagAttribute('hreflang', 'string', 'Define the language of the resource (Only to be used if \'href\' is set).', false);
62+
$this->registerTagAttribute('importance', 'string', 'Define the relative fetch priority of the resource.', false);
63+
$this->registerTagAttribute('integrity', 'string', 'Define base64-encoded cryptographic hash of the resource that allows browsers to verify what they fetch.', false);
64+
$this->registerTagAttribute('media', 'string', 'Define which media type the resources applies to.', false);
65+
$this->registerTagAttribute('referrerpolicy', 'string', 'Define which referrer is sent when fetching the resource.', false);
66+
$this->registerTagAttribute('rel', 'string', 'Define the relationship of the target object to the link object.', false);
67+
$this->registerTagAttribute('sizes', 'string', 'Define the icon size of the resource.', false);
68+
$this->registerTagAttribute('type', 'string', 'Define the MIME type (usually \'text/css\').', false);
69+
$this->registerTagAttribute('nonce', 'string', 'Define a cryptographic nonce (number used once) used to whitelist inline styles in a style-src Content-Security-Policy.', false);
70+
$this->registerArgument(
71+
'identifier',
72+
'string',
73+
'Use this identifier within templates to only inject your CSS once, even though it is added multiple times.',
74+
true
75+
);
76+
$this->registerArgument(
77+
'priority',
78+
'boolean',
79+
'Define whether the CSS should be included before other CSS. CSS will always be output in the <head> tag.',
80+
false,
81+
false
82+
);
2083
$this->registerArgument('scssVariables', 'mixed', 'An optional array of variables to be set inside the SCSS context', false);
2184
$this->registerArgument('outputfile', 'string', '', false);
2285
$this->registerArgument('forcedOutputLocation', 'string', 'force "inline" or "file"', false, '');

Configuration/Services.yaml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
services:
2+
_defaults:
3+
autowire: true
4+
autoconfigure: true
5+
public: false
6+
7+
WapplerSystems\WsScss\:
8+
resource: '../Classes/*'

ext_localconf.php

+3-7
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
<?php
22

3-
use Psr\Http\Message\ServerRequestInterface;
4-
use TYPO3\CMS\Core\Http\ApplicationType;
3+
defined('TYPO3') or die();
4+
5+
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_pagerenderer.php']['render-preProcess']['wsscss'] = \WapplerSystems\WsScss\Hooks\RenderPreProcessorHook::class . '->renderPreProcessorProc';
56

6-
if (($GLOBALS['TYPO3_REQUEST'] ?? null) instanceof ServerRequestInterface
7-
&& ApplicationType::fromRequest($GLOBALS['TYPO3_REQUEST'])->isFrontend()
8-
) {
9-
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_pagerenderer.php']['render-preProcess']['wsscss'] = \WapplerSystems\WsScss\Hooks\RenderPreProcessorHook::class . '->renderPreProcessorProc';
10-
}
117

128
// Caching the pages - default expire 3600 seconds
139
if (!is_array($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['ws_scss'] ?? null)) {

0 commit comments

Comments
 (0)