‪TYPO3CMS  ‪main
TYPO3\CMS\Core\Page\AssetCollector Class Reference
Inheritance diagram for TYPO3\CMS\Core\Page\AssetCollector:
TYPO3\CMS\Core\SingletonInterface

Public Member Functions

 addJavaScript (string $identifier, string $source, array $attributes=[], array $options=[])
 
 addInlineJavaScript (string $identifier, string $source, array $attributes=[], array $options=[])
 
 addStyleSheet (string $identifier, string $source, array $attributes=[], array $options=[])
 
 addInlineStyleSheet (string $identifier, string $source, array $attributes=[], array $options=[])
 
 addMedia (string $fileName, array $additionalInformation)
 
 removeJavaScript (string $identifier)
 
 removeInlineJavaScript (string $identifier)
 
 removeStyleSheet (string $identifier)
 
 removeInlineStyleSheet (string $identifier)
 
 removeMedia (string $identifier)
 
 getMedia ()
 
 getJavaScripts (?bool $priority=null)
 
 getInlineJavaScripts (?bool $priority=null)
 
 getStyleSheets (?bool $priority=null)
 
 getInlineStyleSheets (?bool $priority=null)
 
 hasJavaScript (string $identifier)
 
 hasInlineJavaScript (string $identifier)
 
 hasStyleSheet (string $identifier)
 
 hasInlineStyleSheet (string $identifier)
 
 hasMedia (string $fileName)
 
 updateState (array $newState)
 
 getState ()
 

Protected Member Functions

 filterAssetsPriority (array $assets, ?bool $priority)
 

Protected Attributes

array $javaScripts = []
 
array $inlineJavaScripts = []
 
array $styleSheets = []
 
array $inlineStyleSheets = []
 
array $media = []
 

Private Member Functions

 ensureAllValuesAreSerializable (array $additionalInformation)
 

Detailed Description

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.

Definition at line 41 of file AssetCollector.php.

Member Function Documentation

◆ addInlineJavaScript()

TYPO3\CMS\Core\Page\AssetCollector::addInlineJavaScript ( string  $identifier,
string  $source,
array  $attributes = [],
array  $options = [] 
)
Parameters
string$source‪JavaScript code
array$attributes‪additional HTML <script> tag attributes
array$options‪['priority' => true] means rendering before other tags

Definition at line 73 of file AssetCollector.php.

References TYPO3\CMS\Webhooks\Message\$identifier.

◆ addInlineStyleSheet()

TYPO3\CMS\Core\Page\AssetCollector::addInlineStyleSheet ( string  $identifier,
string  $source,
array  $attributes = [],
array  $options = [] 
)
Parameters
string$source‪stylesheet code
array$attributes‪additional HTML <link> tag attributes
array$options‪['priority' => true] means rendering before other tags

Definition at line 111 of file AssetCollector.php.

References TYPO3\CMS\Webhooks\Message\$identifier.

◆ addJavaScript()

TYPO3\CMS\Core\Page\AssetCollector::addJavaScript ( string  $identifier,
string  $source,
array  $attributes = [],
array  $options = [] 
)
Parameters
string$source‪URI to JavaScript file (allows EXT: syntax)
array$attributes‪additional HTML <script> tag attributes
array$options‪['priority' => true] means rendering before other tags

Definition at line 54 of file AssetCollector.php.

References TYPO3\CMS\Webhooks\Message\$identifier.

◆ addMedia()

TYPO3\CMS\Core\Page\AssetCollector::addMedia ( string  $fileName,
array  $additionalInformation 
)
Parameters
array$additionalInformation‪One dimensional hash map (array with non-numerical keys) with scalar values

Definition at line 128 of file AssetCollector.php.

References TYPO3\CMS\Core\Page\AssetCollector\ensureAllValuesAreSerializable().

◆ addStyleSheet()

TYPO3\CMS\Core\Page\AssetCollector::addStyleSheet ( string  $identifier,
string  $source,
array  $attributes = [],
array  $options = [] 
)
Parameters
string$source‪URI to stylesheet file (allows EXT: syntax)
array$attributes‪additional HTML <link> tag attributes
array$options‪['priority' => true] means rendering before other tags

Definition at line 92 of file AssetCollector.php.

References TYPO3\CMS\Webhooks\Message\$identifier.

◆ ensureAllValuesAreSerializable()

TYPO3\CMS\Core\Page\AssetCollector::ensureAllValuesAreSerializable ( array  $additionalInformation)
private

Definition at line 136 of file AssetCollector.php.

Referenced by TYPO3\CMS\Core\Page\AssetCollector\addMedia().

◆ filterAssetsPriority()

TYPO3\CMS\Core\Page\AssetCollector::filterAssetsPriority ( array  $assets,
?bool  $priority 
)
protected
Parameters
array$assets‪The array to filter
bool | null$priority‪null: no filter; else filters for the given priority

Definition at line 226 of file AssetCollector.php.

References TYPO3\CMS\Webhooks\Message\$identifier.

Referenced by TYPO3\CMS\Core\Page\AssetCollector\getInlineJavaScripts(), TYPO3\CMS\Core\Page\AssetCollector\getInlineStyleSheets(), TYPO3\CMS\Core\Page\AssetCollector\getJavaScripts(), and TYPO3\CMS\Core\Page\AssetCollector\getStyleSheets().

◆ getInlineJavaScripts()

TYPO3\CMS\Core\Page\AssetCollector::getInlineJavaScripts ( ?bool  $priority = null)

◆ getInlineStyleSheets()

TYPO3\CMS\Core\Page\AssetCollector::getInlineStyleSheets ( ?bool  $priority = null)

◆ getJavaScripts()

TYPO3\CMS\Core\Page\AssetCollector::getJavaScripts ( ?bool  $priority = null)

◆ getMedia()

TYPO3\CMS\Core\Page\AssetCollector::getMedia ( )

Definition at line 172 of file AssetCollector.php.

References TYPO3\CMS\Core\Page\AssetCollector\$media.

◆ getState()

TYPO3\CMS\Core\Page\AssetCollector::getState ( )

Definition at line 253 of file AssetCollector.php.

◆ getStyleSheets()

TYPO3\CMS\Core\Page\AssetCollector::getStyleSheets ( ?bool  $priority = null)

◆ hasInlineJavaScript()

TYPO3\CMS\Core\Page\AssetCollector::hasInlineJavaScript ( string  $identifier)

Definition at line 202 of file AssetCollector.php.

References TYPO3\CMS\Webhooks\Message\$identifier.

◆ hasInlineStyleSheet()

TYPO3\CMS\Core\Page\AssetCollector::hasInlineStyleSheet ( string  $identifier)

Definition at line 212 of file AssetCollector.php.

References TYPO3\CMS\Webhooks\Message\$identifier.

◆ hasJavaScript()

TYPO3\CMS\Core\Page\AssetCollector::hasJavaScript ( string  $identifier)

Definition at line 197 of file AssetCollector.php.

References TYPO3\CMS\Webhooks\Message\$identifier.

◆ hasMedia()

TYPO3\CMS\Core\Page\AssetCollector::hasMedia ( string  $fileName)

Definition at line 217 of file AssetCollector.php.

◆ hasStyleSheet()

TYPO3\CMS\Core\Page\AssetCollector::hasStyleSheet ( string  $identifier)

Definition at line 207 of file AssetCollector.php.

References TYPO3\CMS\Webhooks\Message\$identifier.

◆ removeInlineJavaScript()

TYPO3\CMS\Core\Page\AssetCollector::removeInlineJavaScript ( string  $identifier)

Definition at line 148 of file AssetCollector.php.

References TYPO3\CMS\Webhooks\Message\$identifier.

◆ removeInlineStyleSheet()

TYPO3\CMS\Core\Page\AssetCollector::removeInlineStyleSheet ( string  $identifier)

Definition at line 160 of file AssetCollector.php.

References TYPO3\CMS\Webhooks\Message\$identifier.

◆ removeJavaScript()

TYPO3\CMS\Core\Page\AssetCollector::removeJavaScript ( string  $identifier)

Definition at line 142 of file AssetCollector.php.

References TYPO3\CMS\Webhooks\Message\$identifier.

◆ removeMedia()

TYPO3\CMS\Core\Page\AssetCollector::removeMedia ( string  $identifier)

Definition at line 166 of file AssetCollector.php.

References TYPO3\CMS\Webhooks\Message\$identifier.

◆ removeStyleSheet()

TYPO3\CMS\Core\Page\AssetCollector::removeStyleSheet ( string  $identifier)

Definition at line 154 of file AssetCollector.php.

References TYPO3\CMS\Webhooks\Message\$identifier.

◆ updateState()

TYPO3\CMS\Core\Page\AssetCollector::updateState ( array  $newState)

Definition at line 243 of file AssetCollector.php.

Member Data Documentation

◆ $inlineJavaScripts

array TYPO3\CMS\Core\Page\AssetCollector::$inlineJavaScripts = []
protected

Definition at line 44 of file AssetCollector.php.

◆ $inlineStyleSheets

array TYPO3\CMS\Core\Page\AssetCollector::$inlineStyleSheets = []
protected

Definition at line 46 of file AssetCollector.php.

◆ $javaScripts

array TYPO3\CMS\Core\Page\AssetCollector::$javaScripts = []
protected

Definition at line 43 of file AssetCollector.php.

◆ $media

array TYPO3\CMS\Core\Page\AssetCollector::$media = []
protected

Definition at line 47 of file AssetCollector.php.

Referenced by TYPO3\CMS\Core\Page\AssetCollector\getMedia().

◆ $styleSheets

array TYPO3\CMS\Core\Page\AssetCollector::$styleSheets = []
protected

Definition at line 45 of file AssetCollector.php.