AssetResolver
class AssetResolver implements AssetResolverInterface (View source)
The default asset resolver.
Properties
| protected LibraryDiscoveryInterface | $libraryDiscovery | The library discovery service. |
|
| protected LibraryDependencyResolverInterface | $libraryDependencyResolver | The library dependency resolver. |
|
| protected ModuleHandlerInterface | $moduleHandler | The module handler. |
|
| protected ThemeManagerInterface | $themeManager | The theme manager. |
|
| protected LanguageManagerInterface | $languageManager | The language manager. |
|
| protected CacheBackendInterface | $cache | The cache backend. |
Methods
Constructs a new AssetResolver instance.
Returns the CSS assets for the current response's libraries.
Returns the JavaScript settings assets for this response's libraries.
Returns the JavaScript assets for the current response's libraries.
Sorts CSS and JavaScript resources.
Details
__construct(LibraryDiscoveryInterface $library_discovery, LibraryDependencyResolverInterface $library_dependency_resolver, ModuleHandlerInterface $module_handler, ThemeManagerInterface $theme_manager, LanguageManagerInterface $language_manager, CacheBackendInterface $cache)
Constructs a new AssetResolver instance.
protected string[]
getLibrariesToLoad(AttachedAssetsInterface $assets)
Returns the libraries that need to be loaded.
For example, with core/a depending on core/c and core/b on core/d:
array
getCssAssets(AttachedAssetsInterface $assets, bool $optimize)
Returns the CSS assets for the current response's libraries.
It returns the CSS assets in order, according to the SMACSS categories specified in the assets' weights:
- CSS_BASE
- CSS_LAYOUT
- CSS_COMPONENT
- CSS_STATE
- CSS_THEME
protected array
getJsSettingsAssets(AttachedAssetsInterface $assets)
Returns the JavaScript settings assets for this response's libraries.
Gathers all drupalSettings from all libraries in the attached assets collection and merges them.
array
getJsAssets(AttachedAssetsInterface $assets, bool $optimize)
Returns the JavaScript assets for the current response's libraries.
References to JavaScript files are placed in a certain order: first, all 'core' files, then all 'module' and finally all 'theme' JavaScript files are added to the page. Then, all settings are output, followed by 'inline' JavaScript code. If running update.php, all preprocessing is disabled.
Note that hook_js_alter(&$javascript) is called during this function call to allow alterations of the JavaScript during its presentation. The correct way to add JavaScript during hook_js_alter() is to add another element to the $javascript array. See locale_js_alter() for an example of this.
static int
sort($a, $b)
Sorts CSS and JavaScript resources.
This sort order helps optimize front-end performance while providing modules and themes with the necessary control for ordering the CSS and JavaScript appearing on a page.