AssetCollector
class \
- Implements
- SingletonInterface
The Asset Collector is responsible for keeping track of - everything within <script> tags: javascript files and inline javascript code - inline CSS and CSS files
The goal of the asset collector is to:
- utilize a single "runtime-based" store for adding assets of certain kinds that are added to the output
- allow to deal with assets from non-cacheable plugins and cacheable content in the Frontend
- reduce the "power" and flexibility (I'd say it's a burden) of the "god class" PageRenderer.
- reduce the burden of storing everything in PageRenderer
As a side effect this allows to:
- Add a single CSS snippet or CSS file per content block, but assure that the CSS is only added once to the output.
Note on the implementation:
- We use a Singleton to make use of the AssetCollector throughout Frontend process (similar to PageRenderer).
- Although this is not optimal, I don't see any other way to do so in the current code.
Table of Contents
Interfaces
- SingletonInterface
- "empty" interface for singletons (marker interface pattern)
Properties
- $inlineJavaScripts : array
- $inlineStyleSheets : array
- $javaScriptModules : array
- $javaScripts : array
- $media : array
- $styleSheets : array
Methods
- addInlineJavaScript() : self
- addInlineStyleSheet() : self
- addJavaScript() : self
- addJavaScriptModule() : self
- addMedia() : self
- addStyleSheet() : self
- getInlineJavaScripts() : array
- getInlineStyleSheets() : array
- getJavaScriptModules() : array
- getJavaScripts() : array
- getMedia() : array
- getState() : array
- getStyleSheets() : array
- hasInlineJavaScript() : bool
- hasInlineStyleSheet() : bool
- hasJavaScript() : bool
- hasMedia() : bool
- hasStyleSheet() : bool
- removeInlineJavaScript() : self
- removeInlineStyleSheet() : self
- removeJavaScript() : self
- removeMedia() : self
- removeStyleSheet() : self
- updateState() : void
- filterAssetsPriority() : array
Properties
$inlineJavaScripts
protected
array
$inlineJavaScripts
= []
$inlineStyleSheets
protected
array
$inlineStyleSheets
= []
$javaScriptModules
protected
array
$javaScriptModules
= []
$javaScripts
protected
array
$javaScripts
= []
$media
protected
array
$media
= []
$styleSheets
protected
array
$styleSheets
= []
Methods
addInlineJavaScript()
public
addInlineJavaScript(string $identifier, string $source[, array $attributes = [] ][, array $options = [] ]) : self
Parameters
- $identifier : string
- $source : string
-
JavaScript code
- $attributes : array = []
-
additional HTML <script> tag attributes
- $options : array = []
-
['priority' => true] means rendering before other tags
Return values
selfaddInlineStyleSheet()
public
addInlineStyleSheet(string $identifier, string $source[, array $attributes = [] ][, array $options = [] ]) : self
Parameters
- $identifier : string
- $source : string
-
stylesheet code
- $attributes : array = []
-
additional HTML tag attributes
- $options : array = []
-
['priority' => true] means rendering before other tags
Return values
selfaddJavaScript()
public
addJavaScript(string $identifier, string $source[, array $attributes = [] ][, array $options = [] ]) : self
Parameters
- $identifier : string
- $source : string
-
URI to JavaScript file (allows EXT: syntax)
- $attributes : array = []
-
additional HTML <script> tag attributes
- $options : array = []
-
['priority' => true] means rendering before other tags
Return values
selfaddJavaScriptModule()
public
addJavaScriptModule(string $identifier) : self
Parameters
- $identifier : string
-
Bare module identifier like @my/package/Filename.js
Return values
selfaddMedia()
public
addMedia(string $fileName, array $additionalInformation) : self
Deprecated
since TYPO3 v15.0, will be removed in TYPO3 v16.0. Listen to the PSR-14 AfterFileProcessingEvent instead.
Parameters
- $fileName : string
- $additionalInformation : array
-
One dimensional hash map (array with non-numerical keys) with scalar values
Return values
selfaddStyleSheet()
public
addStyleSheet(string $identifier, string $source[, array $attributes = [] ][, array $options = [] ]) : self
Parameters
- $identifier : string
- $source : string
-
URI to stylesheet file (allows EXT: syntax)
- $attributes : array = []
-
additional HTML tag attributes
- $options : array = []
-
['priority' => true] means rendering before other tags
Return values
selfgetInlineJavaScripts()
public
getInlineJavaScripts([bool|null $priority = null ]) : array
Parameters
- $priority : bool|null = null
Return values
arraygetInlineStyleSheets()
public
getInlineStyleSheets([bool|null $priority = null ]) : array
Parameters
- $priority : bool|null = null
Return values
arraygetJavaScriptModules()
public
getJavaScriptModules() : array
Return values
arraygetJavaScripts()
public
getJavaScripts([bool|null $priority = null ]) : array
Parameters
- $priority : bool|null = null
Return values
arraygetMedia()
public
getMedia() : array
Deprecated
since TYPO3 v15.0, will be removed in TYPO3 v16.0. Listen to the PSR-14 AfterFileProcessingEvent instead.
Return values
arraygetState()
public
getState() : array
Internal
Return values
arraygetStyleSheets()
public
getStyleSheets([bool|null $priority = null ]) : array
Parameters
- $priority : bool|null = null
Return values
arrayhasInlineJavaScript()
public
hasInlineJavaScript(string $identifier) : bool
Parameters
- $identifier : string
Return values
boolhasInlineStyleSheet()
public
hasInlineStyleSheet(string $identifier) : bool
Parameters
- $identifier : string
Return values
boolhasJavaScript()
public
hasJavaScript(string $identifier) : bool
Parameters
- $identifier : string
Return values
boolhasMedia()
public
hasMedia(string $fileName) : bool
Deprecated
since TYPO3 v15.0, will be removed in TYPO3 v16.0. Listen to the PSR-14 AfterFileProcessingEvent instead.
Parameters
- $fileName : string
Return values
boolhasStyleSheet()
public
hasStyleSheet(string $identifier) : bool
Parameters
- $identifier : string
Return values
boolremoveInlineJavaScript()
public
removeInlineJavaScript(string $identifier) : self
Parameters
- $identifier : string
Return values
selfremoveInlineStyleSheet()
public
removeInlineStyleSheet(string $identifier) : self
Parameters
- $identifier : string
Return values
selfremoveJavaScript()
public
removeJavaScript(string $identifier) : self
Parameters
- $identifier : string
Return values
selfremoveMedia()
public
removeMedia(string $identifier) : self
Deprecated
since TYPO3 v15.0, will be removed in TYPO3 v16.0. Listen to the PSR-14 AfterFileProcessingEvent instead.
Parameters
- $identifier : string
Return values
selfremoveStyleSheet()
public
removeStyleSheet(string $identifier) : self
Parameters
- $identifier : string
Return values
selfupdateState()
public
updateState(array $newState) : void
Parameters
- $newState : array
Internal
filterAssetsPriority()
protected
filterAssetsPriority(array $assets, bool|null $priority) : array
Parameters
- $assets : array
-
The array to filter
- $priority : bool|null
-
null: no filter; else filters for the given priority