|
6 | 6 |
|
7 | 7 | use ScssPhp\ScssPhp\Exception\SassException;
|
8 | 8 | use TYPO3\CMS\Core\Cache\Exception\NoSuchCacheException;
|
| 9 | +use TYPO3\CMS\Core\Page\AssetCollector; |
9 | 10 | 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; |
11 | 13 | use WapplerSystems\WsScss\Compiler;
|
12 | 14 |
|
13 |
| -class ScssViewHelper extends CssViewHelper |
| 15 | +class ScssViewHelper extends AbstractTagBasedViewHelper |
14 | 16 | {
|
| 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 | + } |
15 | 52 |
|
16 | 53 | public function initializeArguments(): void
|
17 | 54 | {
|
18 | 55 | 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 | + ); |
20 | 83 | $this->registerArgument('scssVariables', 'mixed', 'An optional array of variables to be set inside the SCSS context', false);
|
21 | 84 | $this->registerArgument('outputfile', 'string', '', false);
|
22 | 85 | $this->registerArgument('forcedOutputLocation', 'string', 'force "inline" or "file"', false, '');
|
|
0 commit comments