Skip to content
Snippets Groups Projects
Commit a244e1ad authored by Jonas Eberle's avatar Jonas Eberle Committed by Frank Nägler
Browse files

[TASK] Add documentation for AssetCollector

This adds phpdoc for the public AssetCollector::add...() functions and
notes for users migrating from PageRenderer::add...().

Resolves: #90870
Releases: master
Change-Id: I8896b83f172a0e70ff5bdae61106c3a66d29667c
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/63970


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 66f36c25
Branches
Tags
No related merge requests found
...@@ -65,6 +65,13 @@ class AssetCollector implements SingletonInterface ...@@ -65,6 +65,13 @@ class AssetCollector implements SingletonInterface
*/ */
protected $media = []; protected $media = [];
/**
* @param string $identifier
* @param string $source URI to JavaScript file (allows EXT: syntax)
* @param array $attributes additional HTML <script> tag attributes
* @param array $options ['priority' => true] means rendering before other tags
* @return AssetCollector
*/
public function addJavaScript(string $identifier, string $source, array $attributes = [], array $options = []): self public function addJavaScript(string $identifier, string $source, array $attributes = [], array $options = []): self
{ {
$existingAttributes = $this->javaScripts[$identifier]['attributes'] ?? []; $existingAttributes = $this->javaScripts[$identifier]['attributes'] ?? [];
...@@ -79,6 +86,13 @@ class AssetCollector implements SingletonInterface ...@@ -79,6 +86,13 @@ class AssetCollector implements SingletonInterface
return $this; return $this;
} }
/**
* @param string $identifier
* @param string $source JavaScript code
* @param array $attributes additional HTML <script> tag attributes
* @param array $options ['priority' => true] means rendering before other tags
* @return AssetCollector
*/
public function addInlineJavaScript(string $identifier, string $source, array $attributes = [], array $options = []): self public function addInlineJavaScript(string $identifier, string $source, array $attributes = [], array $options = []): self
{ {
$existingAttributes = $this->inlineJavaScripts[$identifier]['attributes'] ?? []; $existingAttributes = $this->inlineJavaScripts[$identifier]['attributes'] ?? [];
...@@ -93,6 +107,13 @@ class AssetCollector implements SingletonInterface ...@@ -93,6 +107,13 @@ class AssetCollector implements SingletonInterface
return $this; return $this;
} }
/**
* @param string $identifier
* @param string $source URI to stylesheet file (allows EXT: syntax)
* @param array $attributes additional HTML <link> tag attributes
* @param array $options ['priority' => true] means rendering before other tags
* @return AssetCollector
*/
public function addStyleSheet(string $identifier, string $source, array $attributes = [], array $options = []): self public function addStyleSheet(string $identifier, string $source, array $attributes = [], array $options = []): self
{ {
$existingAttributes = $this->styleSheets[$identifier]['attributes'] ?? []; $existingAttributes = $this->styleSheets[$identifier]['attributes'] ?? [];
...@@ -107,6 +128,13 @@ class AssetCollector implements SingletonInterface ...@@ -107,6 +128,13 @@ class AssetCollector implements SingletonInterface
return $this; return $this;
} }
/**
* @param string $identifier
* @param string $source stylesheet code
* @param array $attributes additional HTML <link> tag attributes
* @param array $options ['priority' => true] means rendering before other tags
* @return AssetCollector
*/
public function addInlineStyleSheet(string $identifier, string $source, array $attributes = [], array $options = []): self public function addInlineStyleSheet(string $identifier, string $source, array $attributes = [], array $options = []): self
{ {
$existingAttributes = $this->inlineStyleSheets[$identifier]['attributes'] ?? []; $existingAttributes = $this->inlineStyleSheets[$identifier]['attributes'] ?? [];
......
...@@ -64,6 +64,39 @@ There are also two new ViewHelpers, the :html:`<f:asset.css>` and the - :html:`< ...@@ -64,6 +64,39 @@ There are also two new ViewHelpers, the :html:`<f:asset.css>` and the - :html:`<
alert('hello world'); alert('hello world');
</f:asset.script> </f:asset.script>
Considerations
--------------
Currently, assets registered with the AssetCollector are not included in callbacks of these hooks:
- :php:`$GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['cssCompressHandler']`
- :php:`$GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['jsCompressHandler']`
- :php:`$GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['cssConcatenateHandler']`
- :php:`$GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['jsConcatenateHandler']`
Currently, CSS and JavaScript registered with the AssetCollector will always be rendered after their
PageRenderer counterparts. The order is:
- :html:`<head>`
- :ts:`page.includeJSLibs.forceOnTop`
- :ts:`page.includeJSLibs`
- :ts:`page.includeJS.forceOnTop`
- :ts:`page.includeJS`
- :php:`AssetCollector::addJavaScript()` with 'priority'
- :ts:`page.jsInline`
- :php:`AssetCollector::addInlineJavaScript()` with 'priority'
- :html:`</head>`
- :ts:`page.includeJSFooterlibs.forceOnTop`
- :ts:`page.includeJSFooterlibs`
- :ts:`page.includeJSFooter.forceOnTop`
- :ts:`page.includeJSFooter`
- :php:`AssetCollector::addJavaScript()`
- :ts:`page.jsFooterInline`
- :php:`AssetCollector::addInlineJavaScript()`
Currently, JavaScript registered with AssetCollector is not affected by
:ts:`config.moveJsFromHeaderToFooter`.
Examples Examples
-------- --------
......
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