From 66f36c25d57ddb2a3c68fbc1ae05cdba64254089 Mon Sep 17 00:00:00 2001 From: Jonas Eberle <flightvision@googlemail.com> Date: Sat, 28 Mar 2020 21:43:52 +0100 Subject: [PATCH] [TASK] Change boolean HTML attributes in AssetCollector ViewHelpers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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: TYPO3com <noreply@typo3.com> Tested-by: Frank Nägler <frank.naegler@typo3.org> Tested-by: Andreas Fernandez <a.fernandez@scripting-base.de> Reviewed-by: Frank Nägler <frank.naegler@typo3.org> Reviewed-by: Andreas Fernandez <a.fernandez@scripting-base.de> --- .../Classes/ViewHelpers/Asset/CssViewHelper.php | 8 +++++++- .../Classes/ViewHelpers/Asset/ScriptViewHelper.php | 14 +++++++++++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/typo3/sysext/fluid/Classes/ViewHelpers/Asset/CssViewHelper.php b/typo3/sysext/fluid/Classes/ViewHelpers/Asset/CssViewHelper.php index 532974e2000f..bbc8eac0e4bb 100644 --- a/typo3/sysext/fluid/Classes/ViewHelpers/Asset/CssViewHelper.php +++ b/typo3/sysext/fluid/Classes/ViewHelpers/Asset/CssViewHelper.php @@ -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 = [ diff --git a/typo3/sysext/fluid/Classes/ViewHelpers/Asset/ScriptViewHelper.php b/typo3/sysext/fluid/Classes/ViewHelpers/Asset/ScriptViewHelper.php index 086c7f8d1299..a411d117ef12 100644 --- a/typo3/sysext/fluid/Classes/ViewHelpers/Asset/ScriptViewHelper.php +++ b/typo3/sysext/fluid/Classes/ViewHelpers/Asset/ScriptViewHelper.php @@ -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 = [ -- GitLab