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

[BUGFIX] Do not default to type="text/javascript" in AssetRenderer

This omits type="text/javascript" by default for JavaScript assets.

Resolves: #91000
Releases: master
Change-Id: If8b6a0270a1afe35face8a410beea0736ac43cef
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/64117


Tested-by: default avatarTYPO3com <noreply@typo3.com>
Tested-by: default avatarRiccardo De Contardi <erredeco@gmail.com>
Tested-by: default avatarBenni Mack <benni@typo3.org>
Tested-by: default avatarAndreas Fernandez <a.fernandez@scripting-base.de>
Reviewed-by: default avatarBenni Mack <benni@typo3.org>
Reviewed-by: default avatarAndreas Fernandez <a.fernandez@scripting-base.de>
parent 536a793a
Branches
Tags
No related merge requests found
......@@ -38,9 +38,6 @@ class AssetRenderer
{
$template = '<script%attributes%>%source%</script>';
$assets = $this->assetCollector->getInlineJavaScripts();
foreach ($assets as &$assetData) {
$assetData['attributes']['type'] = $assetData['attributes']['type'] ?? 'text/javascript';
}
return $this->render($assets, $template, $priority);
}
......@@ -50,7 +47,6 @@ class AssetRenderer
$assets = $this->assetCollector->getJavaScripts();
foreach ($assets as &$assetData) {
$assetData['attributes']['src'] = $this->getAbsoluteWebPath($assetData['source']);
$assetData['attributes']['type'] = $assetData['attributes']['type'] ?? 'text/javascript';
}
return $this->render($assets, $template, $priority);
}
......@@ -83,7 +79,11 @@ class AssetRenderer
}
$attributes = $assetData['attributes'];
$attributesString = count($attributes) ? ' ' . GeneralUtility::implodeAttributes($attributes, true) : '';
$results[] = str_replace(['%attributes%', '%source%'], [$attributesString, $assetData['source']], $template);
$results[] = str_replace(
['%attributes%', '%source%'],
[$attributesString, $assetData['source']],
$template
);
}
return implode(LF, $results);
}
......
......@@ -101,18 +101,25 @@ Currently, JavaScript registered with AssetCollector is not affected by
Examples
--------
Add a JavaScript file to the collector with script attribute data-foo="bar"
Add a JavaScript file to the collector with script attribute data-foo="bar":
.. code-block:: php
GeneralUtility::makeInstance(AssetCollector::class)
->addJavaScript('my_ext_foo', 'EXT:my_ext/Resources/Public/JavaScript/foo.js', ['data-foo' => 'bar']]);
->addJavaScript('my_ext_foo', 'EXT:my_ext/Resources/Public/JavaScript/foo.js', ['data-foo' => 'bar']);
Add a JavaScript file to the collector with script attribute :html:`data-foo="bar"` and priority which means rendering before other script tags
Add a JavaScript file to the collector with script attribute :html:`data-foo="bar"` and priority which means rendering before other script tags:
.. code-block:: php
GeneralUtility::makeInstance(AssetCollector::class)
->addJavaScript('my_ext_foo', 'EXT:my_ext/Resources/Public/JavaScript/foo.js', ['data-foo' => 'bar'], ['priority' => true]]);
->addJavaScript('my_ext_foo', 'EXT:my_ext/Resources/Public/JavaScript/foo.js', ['data-foo' => 'bar'], ['priority' => true]);
Add a JavaScript file to the collector with :html:`type="module"` (by default, no type= is output for JavaScript):
.. code-block:: php
GeneralUtility::makeInstance(AssetCollector::class)
->addJavaScript('my_ext_foo', 'EXT:my_ext/Resources/Public/JavaScript/foo.js', ['type' => 'module']);
.. index:: Backend, Frontend, PHP-API, ext:core
......@@ -22,7 +22,7 @@ class AssetDataProvider
[
'css_no_prio' => '<link href="fileadmin/foo.ext" rel="stylesheet" type="text/css" >',
'css_prio' => '',
'js_no_prio' => '<script src="fileadmin/foo.ext" type="text/javascript"></script>',
'js_no_prio' => '<script src="fileadmin/foo.ext"></script>',
'js_prio' => '',
]
],
......@@ -40,7 +40,7 @@ class AssetDataProvider
[
'css_no_prio' => '<link href="typo3/sysext/core/Resource/Public/foo.ext" rel="stylesheet" type="text/css" >',
'css_prio' => '',
'js_no_prio' => '<script src="typo3/sysext/core/Resource/Public/foo.ext" type="text/javascript"></script>',
'js_no_prio' => '<script src="typo3/sysext/core/Resource/Public/foo.ext"></script>',
'js_prio' => '',
]
],
......@@ -58,7 +58,7 @@ class AssetDataProvider
[
'css_no_prio' => '<link href="https://typo3.org/foo.ext" rel="stylesheet" type="text/css" >',
'css_prio' => '',
'js_no_prio' => '<script src="https://typo3.org/foo.ext" type="text/javascript"></script>',
'js_no_prio' => '<script src="https://typo3.org/foo.ext"></script>',
'js_prio' => '',
]
],
......@@ -82,7 +82,7 @@ class AssetDataProvider
[
'css_no_prio' => '<link href="fileadmin/foo.ext" rel="stylesheet" type="text/css" >' . LF . '<link href="typo3/sysext/core/Resource/Public/foo.ext" rel="stylesheet" type="text/css" >',
'css_prio' => '',
'js_no_prio' => '<script src="fileadmin/foo.ext" type="text/javascript"></script>' . LF . '<script src="typo3/sysext/core/Resource/Public/foo.ext" type="text/javascript"></script>',
'js_no_prio' => '<script src="fileadmin/foo.ext"></script>' . LF . '<script src="typo3/sysext/core/Resource/Public/foo.ext"></script>',
'js_prio' => '',
]
],
......@@ -107,7 +107,7 @@ class AssetDataProvider
[
'css_no_prio' => '<link href="typo3/sysext/core/Resource/Public/bar.ext" rel="stylesheet" type="text/css" >' . LF . '<link href="typo3/sysext/core/Resource/Public/foo.ext" rel="stylesheet" type="text/css" >',
'css_prio' => '',
'js_no_prio' => '<script src="typo3/sysext/core/Resource/Public/bar.ext" type="text/javascript"></script>' . LF . '<script src="typo3/sysext/core/Resource/Public/foo.ext" type="text/javascript"></script>',
'js_no_prio' => '<script src="typo3/sysext/core/Resource/Public/bar.ext"></script>' . LF . '<script src="typo3/sysext/core/Resource/Public/foo.ext"></script>',
'js_prio' => '',
]
],
......@@ -127,7 +127,27 @@ class AssetDataProvider
[
'css_no_prio' => '<link rel="foo" href="fileadmin/foo.ext" type="text/css" >',
'css_prio' => '',
'js_no_prio' => '<script rel="foo" src="fileadmin/foo.ext" type="text/javascript"></script>',
'js_no_prio' => '<script rel="foo" src="fileadmin/foo.ext"></script>',
'js_prio' => '',
]
],
'1 file with controlled type' => [
[
['file1', 'fileadmin/foo.ext', ['type' => 'module'], []]
],
[
'file1' => [
'source' => 'fileadmin/foo.ext',
'attributes' => [
'type' => 'module'
],
'options' => [],
]
],
[
'css_no_prio' => '<link type="module" href="fileadmin/foo.ext" rel="stylesheet" >',
'css_prio' => '',
'js_no_prio' => '<script type="module" src="fileadmin/foo.ext"></script>',
'js_prio' => '',
]
],
......@@ -149,7 +169,7 @@ class AssetDataProvider
[
'css_no_prio' => '<link rel="bar" another="keep on override" href="fileadmin/foo.ext" type="text/css" >',
'css_prio' => '',
'js_no_prio' => '<script rel="bar" another="keep on override" src="fileadmin/foo.ext" type="text/javascript"></script>',
'js_no_prio' => '<script rel="bar" another="keep on override" src="fileadmin/foo.ext"></script>',
'js_prio' => '',
]
],
......@@ -170,7 +190,7 @@ class AssetDataProvider
'css_no_prio' => '',
'css_prio' => '<link href="fileadmin/foo.ext" rel="stylesheet" type="text/css" >',
'js_no_prio' => '',
'js_prio' => '<script src="fileadmin/foo.ext" type="text/javascript"></script>',
'js_prio' => '<script src="fileadmin/foo.ext"></script>',
]
],
'1 file with options override' => [
......@@ -191,7 +211,7 @@ class AssetDataProvider
[
'css_no_prio' => '<link href="fileadmin/foo.ext" rel="stylesheet" type="text/css" >',
'css_prio' => '',
'js_no_prio' => '<script src="fileadmin/foo.ext" type="text/javascript"></script>',
'js_no_prio' => '<script src="fileadmin/foo.ext"></script>',
'js_prio' => '',
]
],
......@@ -215,7 +235,7 @@ class AssetDataProvider
[
'css_no_prio' => '<style>foo bar baz</style>',
'css_prio' => '',
'js_no_prio' => '<script type="text/javascript">foo bar baz</script>',
'js_no_prio' => '<script>foo bar baz</script>',
'js_prio' => '',
]
],
......@@ -239,7 +259,7 @@ class AssetDataProvider
[
'css_no_prio' => '<style>foo bar baz</style>' . LF . '<style>bar baz foo</style>',
'css_prio' => '',
'js_no_prio' => '<script type="text/javascript">foo bar baz</script>' . LF . '<script type="text/javascript">bar baz foo</script>',
'js_no_prio' => '<script>foo bar baz</script>' . LF . '<script>bar baz foo</script>',
'js_prio' => '',
]
],
......@@ -264,7 +284,7 @@ class AssetDataProvider
[
'css_no_prio' => '<style>baz foo bar</style>' . LF . '<style>bar baz foo</style>',
'css_prio' => '',
'js_no_prio' => '<script type="text/javascript">baz foo bar</script>' . LF . '<script type="text/javascript">bar baz foo</script>',
'js_no_prio' => '<script>baz foo bar</script>' . LF . '<script>bar baz foo</script>',
'js_prio' => '',
]
],
......@@ -284,7 +304,7 @@ class AssetDataProvider
[
'css_no_prio' => '<style rel="foo">foo bar baz</style>',
'css_prio' => '',
'js_no_prio' => '<script rel="foo" type="text/javascript">foo bar baz</script>',
'js_no_prio' => '<script rel="foo">foo bar baz</script>',
'js_prio' => '',
]
],
......@@ -306,7 +326,7 @@ class AssetDataProvider
[
'css_no_prio' => '<style rel="bar" another="keep on override">foo bar baz</style>',
'css_prio' => '',
'js_no_prio' => '<script rel="bar" another="keep on override" type="text/javascript">foo bar baz</script>',
'js_no_prio' => '<script rel="bar" another="keep on override">foo bar baz</script>',
'js_prio' => '',
]
],
......@@ -327,7 +347,7 @@ class AssetDataProvider
'css_no_prio' => '',
'css_prio' => '<style>foo bar baz</style>',
'js_no_prio' => '',
'js_prio' => '<script type="text/javascript">foo bar baz</script>',
'js_prio' => '<script>foo bar baz</script>',
]
],
'simple data with options override' => [
......@@ -348,7 +368,7 @@ class AssetDataProvider
[
'css_no_prio' => '<style>foo bar baz</style>',
'css_prio' => '',
'js_no_prio' => '<script type="text/javascript">foo bar baz</script>',
'js_no_prio' => '<script>foo bar baz</script>',
'js_prio' => '',
]
],
......
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