TYPO3 v15 dev-main snapshot ()

This commit is contained in:
2026-08-10 22:31:20 +02:00
commit c7a46689ff
115 changed files with 11736 additions and 0 deletions
+129
View File
@@ -0,0 +1,129 @@
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Fluid\ViewHelpers\Asset;
use TYPO3\CMS\Core\Page\AssetCollector;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper;
use TYPO3Fluid\Fluid\Core\ViewHelper\TagBuilder;
/**
* ViewHelper to add CSS to the TYPO3 AssetCollector. Either a file or inline CSS can be added.
*
* ```
* <f:asset.css identifier="identifier123" href="EXT:my_ext/Resources/Public/Css/foo.css" inline="0" />
* <f:asset.css identifier="identifier123">
* .foo { color: black; }
* </f:asset.css>
* ```
*
* @see https://docs.typo3.org/permalink/t3viewhelper:typo3-fluid-asset-css
*/
final class CssViewHelper extends AbstractTagBasedViewHelper
{
/**
* This VH does not produce direct output, thus does not need to be wrapped in an escaping node
*
* @var bool
*/
protected $escapeOutput = false;
/**
* Rendered children string is passed as CSS code,
* there is no point in HTML encoding anything from that.
*
* @var bool
*/
protected $escapeChildren = true;
public function __construct(
private readonly AssetCollector $assetCollector,
) {
parent::__construct();
}
public function initialize(): void
{
// Add a tag builder, that does not html encode values, because rendering with encoding happens in AssetRenderer
$this->setTagBuilder(
new class extends TagBuilder {
public function addAttribute($attributeName, $attributeValue, $escapeSpecialCharacters = false): void
{
parent::addAttribute($attributeName, $attributeValue, false);
}
}
);
parent::initialize();
}
public function initializeArguments(): void
{
parent::initializeArguments();
$this->registerArgument('disabled', 'bool', 'Define whether or not the described stylesheet should be loaded and applied to the document.');
$this->registerArgument('csp', 'bool', 'Whether to collect a CSP hash value for this asset (default: true for external files, false for inline)', false, null);
$this->registerArgument('identifier', 'string', 'Use this identifier within templates to only inject your CSS once, even though it is added multiple times.', true);
$this->registerArgument('priority', 'boolean', 'Define whether the CSS should be included before other CSS. CSS will always be output in the <head> tag.', false, false);
$this->registerArgument('inline', 'bool', 'Define whether or not the referenced file should be loaded as inline styles (Only to be used if \'href\' is set).', false, false);
}
public function render(): string
{
$identifier = (string)$this->arguments['identifier'];
$attributes = $this->tag->getAttributes();
// boolean attributes shall output attr="attr" if set
if ($this->arguments['disabled'] ?? false) {
$attributes['disabled'] = 'disabled';
}
$file = $attributes['href'] ?? null;
unset($attributes['href']);
$isExternalFile = $file !== null && !($this->arguments['inline'] ?? false);
$useCsp = $this->resolveCspOption($isExternalFile);
$options = [
'priority' => $this->arguments['priority'],
'csp' => $useCsp,
];
if ($file !== null) {
if ($this->arguments['inline'] ?? false) {
$content = @file_get_contents(GeneralUtility::getFileAbsFileName(trim($file)));
if ($content !== false) {
$this->assetCollector->addInlineStyleSheet($identifier, $content, $attributes, $options);
}
} else {
$this->assetCollector->addStyleSheet($identifier, $file, $attributes, $options);
}
} else {
$content = (string)$this->renderChildren();
if ($content !== '') {
$this->assetCollector->addInlineStyleSheet($identifier, $content, $attributes, $options);
}
}
return '';
}
private function resolveCspOption(bool $defaultForStatic): bool
{
$csp = $this->arguments['csp'];
if ($csp !== null) {
return (bool)$csp;
}
// Default: true for external files (allows hash collection), false for inline
return $defaultForStatic;
}
}
@@ -0,0 +1,59 @@
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Fluid\ViewHelpers\Asset;
use TYPO3\CMS\Core\Page\AssetCollector;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
/**
* ViewHelper to add JavaScript modules to the TYPO3 AssetCollector.
*
* Examples
* ========
*
* ::
*
* <f:asset.module identifier="@my/package/filename.js"/>
*
* Details
* =======
*
* In the AssetCollector, the "identifier" attribute is used as a unique identifier. Thus, if modules are added multiple
* times using the same module identifier, the asset will only be served once.
*
* @see https://docs.typo3.org/permalink/t3viewhelper:typo3-fluid-asset-module
*/
final class ModuleViewHelper extends AbstractViewHelper
{
public function __construct(
private readonly AssetCollector $assetCollector,
) {}
public function initializeArguments(): void
{
parent::initializeArguments();
$this->registerArgument('identifier', 'string', 'Bare module identifier like "@my/package/filename.js".', true);
}
public function render(): string
{
$identifier = (string)$this->arguments['identifier'];
$this->assetCollector->addJavaScriptModule($identifier);
return '';
}
}
@@ -0,0 +1,133 @@
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Fluid\ViewHelpers\Asset;
use TYPO3\CMS\Core\Page\AssetCollector;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper;
use TYPO3Fluid\Fluid\Core\ViewHelper\TagBuilder;
/**
* ViewHelper to add JavaScript to the TYPO3 AssetCollector. Either a file or inline JavaScript can be added.
*
* ```
* <f:asset.script identifier="identifier123" src="EXT:my_ext/Resources/Public/JavaScript/foo.js" inline="0" />
* <f:asset.script identifier="identifier123">
* alert('hello world');
* </f:asset.script>
* ```
*
* @see https://docs.typo3.org/permalink/t3viewhelper:typo3-fluid-asset-script
*/
final class ScriptViewHelper extends AbstractTagBasedViewHelper
{
/**
* This VH does not produce direct output, thus does not need to be wrapped in an escaping node
*
* @var bool
*/
protected $escapeOutput = false;
/**
* Rendered children string is passed as JavaScript code,
* there is no point in HTML encoding anything from that.
*
* @var bool
*/
protected $escapeChildren = false;
public function __construct(
private readonly AssetCollector $assetCollector,
) {
parent::__construct();
}
public function initialize(): void
{
// Add a tag builder, that does not html encode values, because rendering with encoding happens in AssetRenderer
$this->setTagBuilder(
new class extends TagBuilder {
public function addAttribute($attributeName, $attributeValue, $escapeSpecialCharacters = false): void
{
parent::addAttribute($attributeName, $attributeValue, false);
}
}
);
parent::initialize();
}
public function initializeArguments(): void
{
parent::initializeArguments();
$this->registerArgument('async', 'bool', 'Define that the script will be fetched in parallel to parsing and evaluation.');
$this->registerArgument('defer', 'bool', 'Define that the script is meant to be executed after the document has been parsed.');
$this->registerArgument('nomodule', 'bool', 'Define that the script should not be executed in browsers that support ES2015 modules.');
$this->registerArgument('csp', 'bool', 'Whether to collect a CSP hash value for this asset (default: true for external files, false for inline)', false, null);
$this->registerArgument('identifier', 'string', 'Use this identifier within templates to only inject your JS once, even though it is added multiple times.', true);
$this->registerArgument('priority', 'boolean', 'Define whether the JavaScript should be put in the <head> tag above-the-fold or somewhere in the body part.', false, false);
$this->registerArgument('inline', 'bool', 'Define whether or not the referenced file should be loaded as inline script (Only to be used if \'src\' is set).', false, false);
}
public function render(): string
{
$identifier = (string)$this->arguments['identifier'];
$attributes = $this->tag->getAttributes();
// boolean attributes shall output attr="attr" if set
foreach (['async', 'defer', 'nomodule'] as $attribute) {
if ($this->arguments[$attribute] ?? false) {
$attributes[$attribute] = $attribute;
}
}
$src = $attributes['src'] ?? null;
unset($attributes['src']);
$isExternalFile = $src !== null && !($this->arguments['inline'] ?? false);
$useCsp = $this->resolveCspOption($isExternalFile);
$options = [
'priority' => $this->arguments['priority'],
'csp' => $useCsp,
];
if ($src !== null) {
if ($this->arguments['inline'] ?? false) {
$content = @file_get_contents(GeneralUtility::getFileAbsFileName(trim($src)));
if ($content !== false) {
$this->assetCollector->addInlineJavaScript($identifier, $content, $attributes, $options);
}
} else {
$this->assetCollector->addJavaScript($identifier, $src, $attributes, $options);
}
} else {
$content = (string)$this->renderChildren();
if ($content !== '') {
$this->assetCollector->addInlineJavaScript($identifier, $content, $attributes, $options);
}
}
return '';
}
private function resolveCspOption(bool $defaultForStatic): bool
{
$csp = $this->arguments['csp'];
if ($csp !== null) {
return (bool)$csp;
}
// Default: true for external files (allows hash collection), false for inline
return $defaultForStatic;
}
}
@@ -0,0 +1,55 @@
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Fluid\ViewHelpers\Asset;
use TYPO3\CMS\Core\Security\ContentSecurityPolicy\Directive;
use TYPO3\CMS\Core\Security\ContentSecurityPolicy\DirectiveHashCollection;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
/**
* ViewHelper for inline style attributes that need CSP hash coverage via `style-src-attr`.
*
* When `csp` is true (default), the style value is hashed and registered with the
* HashCollection so that the CSP header includes the corresponding `sha256-...` hash.
*
* Usage:
* ```
* <div style="{f:asset.styleAttr(value: 'color: green; text-decoration: underline;', csp: true)}">...</div>
* ```
*
* @see https://docs.typo3.org/permalink/t3viewhelper:typo3-fluid-asset-styleattr
*/
final class StyleAttrViewHelper extends AbstractViewHelper
{
public function __construct(private readonly DirectiveHashCollection $directiveHashCollection) {}
public function initializeArguments(): void
{
$this->registerArgument('value', 'string', 'The inline style value (e.g. "color: green; text-decoration: underline;")', true);
$this->registerArgument('csp', 'bool', 'Whether to collect a CSP hash for this style value', false, true);
}
public function render(): string
{
$value = trim($this->arguments['value'] ?? $this->renderChildren());
if ($this->arguments['csp'] ?? true) {
$this->directiveHashCollection->addInlineHash(Directive::StyleSrcAttr, $value);
}
return $value;
}
}