WebAssetManager
Implements WebAssetManagerInterfaceWeb Asset Manager class
| since |
4.0.0 |
|---|---|
| package |
Joomla CMS |
Methods
__call
Adds support for magic method calls
__call( method, mixed||string|int arguments) :
| throws |
|
|---|---|
| since |
4.0.0 |
Arguments
- method
stringA method name- arguments
array<string|int, mixed>Arguments for a method
Response
mixed
__construct
Class constructor
__construct(\Joomla\CMS\WebAsset\WebAssetRegistry registry) :
addInline
Add a new inline content asset.
addInline( type, \Joomla\CMS\WebAsset\WebAssetItem|string content, mixed||string|int options = [], mixed||string|int attributes = [], mixed||string|int dependencies = []) :
Allow to register WebAssetItem instance in the registry, by call addInline($type, $assetInstance) Or create an asset on fly (from name and Uri) and register in the registry, by call addInline($type, $content, $options ....)
| since |
4.0.0 |
|---|---|
| throws |
|
Arguments
- type
stringThe asset type, script or style- content
WebAssetItem|stringThe content to of inline asset- options
array<string|int, mixed>Additional options for the asset- attributes
array<string|int, mixed>Attributes for the asset- dependencies
array<string|int, mixed>Asset dependencies
Response
self
addInlineScript
addInlineScript(\Joomla\CMS\WebAsset\WebAssetItem|string content, options = = '[]', attributes = = '[]', dependencies = = '[]') : \Joomla\CMS\WebAsset\WebAssetManager
addInlineStyle
addInlineStyle(\Joomla\CMS\WebAsset\WebAssetItem|string content, options = = '[]', attributes = = '[]', dependencies = = '[]') : \Joomla\CMS\WebAsset\WebAssetManager
assetExists
Helper method to check whether the asset exists in the registry.
assetExists( type, name) :
| since |
4.0.0 |
|---|
Arguments
- type
stringAsset type, script or style- name
stringAsset name
Response
bool
calculateOrderOfActiveAssets
Calculate weight of active Assets, by its Dependencies
calculateOrderOfActiveAssets( type) : \Joomla\CMS\WebAsset\WebAssetItem||string|int
| since |
4.0.0 |
|---|
Arguments
- type
stringThe asset type, script or style
Response
array<string|int, WebAssetItem>
callOnAttachCallback
A helper method to call onAttachCallback for script assets that implements WebAssetAttachBehaviorInterface
callOnAttachCallback(mixed||string|int assets, \Joomla\CMS\Document\Document document, mixed||string|int cache = []) : mixed||string|int
| since |
5.1.0 |
|---|
Arguments
- assets
array<string|int, mixed>Array of assets- document
DocumentDocument instance to attach- cache
array<string|int, mixed>Array of object ids which callback was already called
Response
array<string|int, mixed>Array of object ids for which callback was called
disableAsset
Deactivate an asset item, so it will not be attached to a Document
disableAsset( type, name) :
| throws |
|
|---|---|
| since |
4.0.0 |
Arguments
- type
stringThe asset type, script or style- name
stringThe asset name
Response
self
disablePreset
disablePreset( name) : \Joomla\CMS\WebAsset\WebAssetManager
disablePresetItems
Deactivate list of assets provided by Preset item.
disablePresetItems( name) :
| throws |
|
|---|---|
| since |
4.0.0 |
Arguments
- name
stringThe asset name
Response
self
disableScript
disableScript( name) : \Joomla\CMS\WebAsset\WebAssetManager
disableStyle
disableStyle( name) : \Joomla\CMS\WebAsset\WebAssetManager
enableDependencies
Update Dependencies state for all active Assets or only for given
enableDependencies(string type = null, \Joomla\CMS\WebAsset\WebAssetItem asset = null) :
| since |
4.0.0 |
|---|
Arguments
- type
string|nullThe asset type, script or style- asset
WebAssetItem|nullThe asset instance to which need to enable dependencies
Response
self
filterOutInlineAssets
Helper method to filter an inline assets
filterOutInlineAssets(\Joomla\CMS\WebAsset\WebAssetItem||string|int &assets) : \Joomla\CMS\WebAsset\WebAssetItem||string|int
| since |
4.0.0 |
|---|
Arguments
- assets
array<string|int, WebAssetItem>Reference to a full list of active assets
Response
array<string|int, WebAssetItem>Array of inline assets
getAsset
Helper method to get the asset from the registry.
getAsset( type, name) : \Joomla\CMS\WebAsset\WebAssetItemInterface
| throws |
|
|---|---|
| since |
4.0.0 |
Arguments
- type
stringAsset type, script or style- name
stringAsset name
Response
getAssets
Get all active assets, optionally sort them to follow the dependency Graph
getAssets( type, sort = false) : \Joomla\CMS\WebAsset\WebAssetItem||string|int
| throws |
|
|---|---|
| since |
4.0.0 |
Arguments
- type
stringThe asset type, script or style- sort
boolWhether we need to sort the assets to follow the dependency Graph
Response
array<string|int, WebAssetItem>
getAssetState
Get a state for the Asset
getAssetState( type, name) :
| throws |
|
|---|---|
| since |
4.0.0 |
Arguments
- type
stringThe asset type, script or style- name
stringThe asset name
Response
int
getConnectionsGraph
Build Graph of Outgoing and Incoming connections for given assets.
getConnectionsGraph(\Joomla\CMS\WebAsset\WebAssetItem||string|int assets) : mixed||string|int
| since |
4.0.0 |
|---|
Arguments
- assets
array<string|int, WebAssetItem>Asset instances
Response
array<string|int, mixed>
getDependenciesForAsset
Return dependencies for Asset as array of WebAssetItem objects
getDependenciesForAsset( type, \Joomla\CMS\WebAsset\WebAssetItem asset, recursively = false, string recursionType = null, \Joomla\CMS\WebAsset\WebAssetItem recursionRoot = null) : mixed||string|int
| throws |
|
|---|---|
| since |
4.0.0 |
Arguments
- type
stringThe asset type, script or style- asset
WebAssetItemAsset instance- recursively
boolWhether to search for dependency recursively- recursionType
string|nullThe type of initial item to prevent loop- recursionRoot
WebAssetItem|nullInitial item to prevent loop
Response
array<string|int, mixed>
getInlineRelation
Helper method to calculate inline to non inline relation (before/after positions).
getInlineRelation(\Joomla\CMS\WebAsset\WebAssetItem||string|int assets) : mixed||string|int
Return associated array, which contain dependency (handle) name as key, and list of inline items for each position. Example: ['handle.name' => ['before' => ['inline1', 'inline2'], 'after' => ['inline3', 'inline4']]]
Note: If inline asset have a multiple dependencies, then will be used last one from the list for positioning
| since |
4.0.0 |
|---|
Arguments
- assets
array<string|int, WebAssetItem>The assets list
Response
array<string|int, mixed>
getManagerState
Get the manager state. A collection of registry files and active asset names (per type).
getManagerState() : mixed||string|int
| since |
4.0.0 |
|---|
Response
array<string|int, mixed>
getRegistry
Get associated registry instance
getRegistry() : \Joomla\CMS\WebAsset\WebAssetRegistry
isAssetActive
Check whether the asset are enabled
isAssetActive( type, name) :
| throws |
|
|---|---|
| since |
4.0.0 |
Arguments
- type
stringThe asset type, script or style- name
stringThe asset name
Response
bool
lock
Lock the manager to prevent further modifications
lock() :
| since |
4.0.0 |
|---|
Response
self
registerAndUsePreset
registerAndUsePreset(\Joomla\CMS\WebAsset\WebAssetItem|string asset, uri = = '\'\'', options = = '[]', attributes = = '[]', dependencies = = '[]') : \Joomla\CMS\WebAsset\WebAssetManager
Arguments
- asset
WebAssetItem|string- uri
string- options
mixed- attributes
mixed- dependencies
mixed
Response
registerAndUseScript
registerAndUseScript(\Joomla\CMS\WebAsset\WebAssetItem|string asset, uri = = '\'\'', options = = '[]', attributes = = '[]', dependencies = = '[]') : \Joomla\CMS\WebAsset\WebAssetManager
Arguments
- asset
WebAssetItem|string- uri
string- options
mixed- attributes
mixed- dependencies
mixed
Response
registerAndUseStyle
registerAndUseStyle(\Joomla\CMS\WebAsset\WebAssetItem|string asset, uri = = '\'\'', options = = '[]', attributes = = '[]', dependencies = = '[]') : \Joomla\CMS\WebAsset\WebAssetManager
Arguments
- asset
WebAssetItem|string- uri
string- options
mixed- attributes
mixed- dependencies
mixed
Response
registerAsset
Register a new asset.
registerAsset( type, \Joomla\CMS\WebAsset\WebAssetItem|string asset, uri = '', mixed||string|int options = [], mixed||string|int attributes = [], mixed||string|int dependencies = []) :
Allow to register WebAssetItem instance in the registry, by call registerAsset($type, $assetInstance) Or create an asset on fly (from name and Uri) and register in the registry, by call registerAsset($type, $assetName, $uri, $options ....)
| since |
4.0.0 |
|---|---|
| throws |
|
Arguments
- type
stringThe asset type, script or style- asset
WebAssetItem|stringThe asset name or instance to register- uri
stringThe URI for the asset- options
array<string|int, mixed>Additional options for the asset- attributes
array<string|int, mixed>Attributes for the asset- dependencies
array<string|int, mixed>Asset dependencies
Response
self
registerPreset
registerPreset(\Joomla\CMS\WebAsset\WebAssetItem|string asset, uri = = '\'\'', options = = '[]', attributes = = '[]', dependencies = = '[]') : \Joomla\CMS\WebAsset\WebAssetManager
Arguments
- asset
WebAssetItem|string- uri
string- options
mixed- attributes
mixed- dependencies
mixed
Response
registerScript
registerScript(\Joomla\CMS\WebAsset\WebAssetItem|string asset, uri = = '\'\'', options = = '[]', attributes = = '[]', dependencies = = '[]') : \Joomla\CMS\WebAsset\WebAssetManager
Arguments
- asset
WebAssetItem|string- uri
string- options
mixed- attributes
mixed- dependencies
mixed
Response
registerStyle
registerStyle(\Joomla\CMS\WebAsset\WebAssetItem|string asset, uri = = '\'\'', options = = '[]', attributes = = '[]', dependencies = = '[]') : \Joomla\CMS\WebAsset\WebAssetManager
Arguments
- asset
WebAssetItem|string- uri
string- options
mixed- attributes
mixed- dependencies
mixed
Response
reset
Clears all collected items.
reset() :
| since |
4.1.1 |
|---|
Response
self
useAsset
Enable an asset item to be attached to a Document
useAsset( type, name) :
| throws |
|
|---|---|
| since |
4.0.0 |
Arguments
- type
stringThe asset type, script or style- name
stringThe asset name
Response
self
usePreset
usePreset( name) : \Joomla\CMS\WebAsset\WebAssetManager
usePresetItems
Enable list of assets provided by Preset item.
usePresetItems( name) :
"Preset" a special kind of asset that hold a list of assets that has to be enabled, same as direct call of useAsset() to each of item in list. Can hold mixed types of assets (script, style, another preset, etc), the type provided after # symbol, after the asset name, example: foo#style, bar#script.
The method call useAsset() internally for each of its dependency, this is important for keeping FIFO order of enabled items. The Preset not a strict asset, and each of its dependency can be safely disabled by use of disableAsset() later.
| throws |
|
|---|---|
| since |
4.0.0 |
Arguments
- name
stringThe asset name
Response
self
useScript
useScript( name) : \Joomla\CMS\WebAsset\WebAssetManager
useStyle
useStyle( name) : \Joomla\CMS\WebAsset\WebAssetManager
Constants
ASSET_STATE_INACTIVE
Mark inactive asset
| Value | 0 |
|---|---|
| since |
4.0.0 |
Type(s)
int
ASSET_STATE_ACTIVE
Mark active asset. Just enabled, but WITHOUT dependency resolved
| Value | 1 |
|---|---|
| since |
4.0.0 |
Type(s)
int
ASSET_STATE_DEPENDENCY
Mark active asset that is enabled as dependency to another asset
| Value | 2 |
|---|---|
| since |
4.0.0 |
Type(s)
int
Properties
activeAssets
A list of active assets (including their dependencies).
Array of Name => State
| since |
4.0.0 |
|---|
Type(s)
array<string|int, mixed>
locked
Internal marker to check the manager state, to prevent use of the manager after an assets are rendered
| since |
4.0.0 |
|---|
Type(s)
bool
dependenciesIsActual
Internal marker to keep track when need to recheck dependencies
| since |
4.0.0 |
|---|
Type(s)
bool
sortedAssets
A cache holder for list of sorted assets, used by getAssets() method This is emptied when dependencies actualised, see enableDependencies() method
| since |
5.1.0 |
|---|
Type(s)
array<string|int, mixed>