Skip to content
Snippets Groups Projects
Commit 66f36c25 authored by Jonas Eberle's avatar Jonas Eberle Committed by Andreas Fernandez
Browse files

[TASK] Change boolean HTML attributes in AssetCollector ViewHelpers

As boolean HTML attributes shall either have a value equal to the
attribute name (e.g. async="async") or have no value at all (only allowed
in HTML5), the ViewHelper reflects that now.

All boolean HTML attributes on <script> (async, defer, nomodule) and
<link> (disabled) have been changed to Fluid "bool" ("0" and "false" is
false, rest is true).

This allows using the ViewHelpers with e.g. async="1" which before would
have output <script async="1">. Now it is registered as async="async"
with AssetCollector.

References:
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link

Resolves: #90871
Releases: master
Change-Id: I5052ff6ad86e14a9b55f507ba0f3dcf7ea3010e6
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/63996


Tested-by: default avatarTYPO3com <noreply@typo3.com>
Tested-by: default avatarFrank Nägler <frank.naegler@typo3.org>
Tested-by: default avatarAndreas Fernandez <a.fernandez@scripting-base.de>
Reviewed-by: default avatarFrank Nägler <frank.naegler@typo3.org>
Reviewed-by: default avatarAndreas Fernandez <a.fernandez@scripting-base.de>
parent 14ef48ac
Branches
Tags
No related merge requests found
......@@ -56,7 +56,7 @@ class CssViewHelper extends AbstractTagBasedViewHelper
parent::registerUniversalTagAttributes();
$this->registerTagAttribute('as', 'string', '', false);
$this->registerTagAttribute('crossorigin', 'string', '', false);
$this->registerTagAttribute('disabled', 'string', '', false);
$this->registerTagAttribute('disabled', 'bool', '', false);
$this->registerTagAttribute('href', 'string', '', false);
$this->registerTagAttribute('hreflang', 'string', '', false);
$this->registerTagAttribute('importance', 'string', '', false);
......@@ -86,6 +86,12 @@ class CssViewHelper extends AbstractTagBasedViewHelper
{
$identifier = (string)$this->arguments['identifier'];
$attributes = $this->tag->getAttributes();
// boolean attributes shall output attr="attr" if set
if ($attributes['disabled'] ?? false) {
$attributes['disabled'] = 'disabled';
}
$file = $this->tag->getAttribute('href');
unset($attributes['href']);
$options = [
......
......@@ -54,11 +54,11 @@ class ScriptViewHelper extends AbstractTagBasedViewHelper
{
parent::initializeArguments();
parent::registerUniversalTagAttributes();
$this->registerTagAttribute('async', 'string', '', false);
$this->registerTagAttribute('async', 'bool', '', false);
$this->registerTagAttribute('crossorigin', 'string', '', false);
$this->registerTagAttribute('defer', 'string', '', false);
$this->registerTagAttribute('defer', 'bool', '', false);
$this->registerTagAttribute('integrity', 'string', '', false);
$this->registerTagAttribute('nomodule', 'string', '', false);
$this->registerTagAttribute('nomodule', 'bool', '', false);
$this->registerTagAttribute('nonce', 'string', '', false);
$this->registerTagAttribute('referrerpolicy', 'string', '', false);
$this->registerTagAttribute('src', 'string', '', false);
......@@ -82,6 +82,14 @@ class ScriptViewHelper extends AbstractTagBasedViewHelper
{
$identifier = (string)$this->arguments['identifier'];
$attributes = $this->tag->getAttributes();
// boolean attributes shall output attr="attr" if set
foreach (['async', 'defer', 'nomodule'] as $_attr) {
if ($attributes[$_attr] ?? false) {
$attributes[$_attr] = $_attr;
}
}
$src = $this->tag->getAttribute('src');
unset($attributes['src']);
$options = [
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment