Drupal 8  8.0.2
AssetResolver Class Reference
Inheritance diagram for AssetResolver:

Public Member Functions

 __construct (LibraryDiscoveryInterface $library_discovery, LibraryDependencyResolverInterface $library_dependency_resolver, ModuleHandlerInterface $module_handler, ThemeManagerInterface $theme_manager, LanguageManagerInterface $language_manager, CacheBackendInterface $cache)
 
 getCssAssets (AttachedAssetsInterface $assets, $optimize)
 
 getJsAssets (AttachedAssetsInterface $assets, $optimize)
 

Static Public Member Functions

static sort ($a, $b)
 

Protected Member Functions

 getLibrariesToLoad (AttachedAssetsInterface $assets)
 
 getJsSettingsAssets (AttachedAssetsInterface $assets)
 

Protected Attributes

 $libraryDiscovery
 
 $libraryDependencyResolver
 
 $moduleHandler
 
 $themeManager
 
 $languageManager
 
 $cache
 

Detailed Description

The default asset resolver.

Constructor & Destructor Documentation

__construct ( LibraryDiscoveryInterface  $library_discovery,
LibraryDependencyResolverInterface  $library_dependency_resolver,
ModuleHandlerInterface  $module_handler,
ThemeManagerInterface  $theme_manager,
LanguageManagerInterface  $language_manager,
CacheBackendInterface  $cache 
)

Constructs a new AssetResolver instance.

Parameters
\Drupal\Core\Asset\LibraryDiscoveryInterface$library_discoveryThe library discovery service.
\Drupal\Core\Asset\LibraryDependencyResolverInterface$library_dependency_resolverThe library dependency resolver.
\Drupal\Core\Extension\ModuleHandlerInterface$module_handlerThe module handler.
\Drupal\Core\Theme\ThemeManagerInterface$theme_managerThe theme manager.
\Drupal\Core\Language\LanguageManagerInterface$language_managerThe language manager.
\Drupal\Core\Cache\CacheBackendInterface$cacheThe cache backend.

References Drupal\cache(), Drupal\languageManager(), and Drupal\moduleHandler().

Here is the call graph for this function:

Member Function Documentation

getCssAssets ( AttachedAssetsInterface  $assets,
  $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
    See Also
    https://www.drupal.org/node/1887918#separate-concerns This ensures proper cascading of styles so themes can easily override module styles through CSS selectors.
    Themes may replace module-defined CSS files by adding a stylesheet with the same filename. For example, themes/bartik/system-menus.css would replace modules/system/system-menus.css. This allows themes to override complete CSS files, rather than specific selectors, when necessary.
Also invokes hook_css_alter(), to allow CSS assets to be altered.
Parameters
\Drupal\Core\Asset\AttachedAssetsInterface$assetsThe assets attached to the current response.
bool$optimizeWhether to apply the CSS asset collection optimizer, to return an optimized CSS asset collection rather than an unoptimized one.
Returns
array A (possibly optimized) collection of CSS assets.
}

Implements AssetResolverInterface.

References Drupal\cache(), CacheBackendInterface\CACHE_PERMANENT, AssetResolver\getLibrariesToLoad(), Crypt\hashBase64(), Drupal\moduleHandler(), and Drupal\service().

Here is the call graph for this function:

getJsAssets ( AttachedAssetsInterface  $assets,
  $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, deriving from drupal_js_defaults(). See locale_js_alter() for an example of this.

Parameters
\Drupal\Core\Asset\AttachedAssetsInterface$assetsThe assets attached to the current response. Note that this object is modified to reflect the final JavaScript settings assets.
bool$optimizeWhether to apply the JavaScript asset collection optimizer, to return optimized JavaScript asset collections rather than an unoptimized ones.
Returns
array A nested array containing 2 values:
  • at index zero: the (possibly optimized) collection of JavaScript assets for the top of the page
  • at index one: the (possibly optimized) collection of JavaScript assets for the bottom of the page
}

Implements AssetResolverInterface.

References Drupal\cache(), CacheBackendInterface\CACHE_PERMANENT, AttachedAssetsInterface\getAlreadyLoadedLibraries(), AssetResolver\getJsSettingsAssets(), AssetResolver\getLibrariesToLoad(), AttachedAssetsInterface\getSettings(), Crypt\hashBase64(), Drupal\languageManager(), NestedArray\mergeDeepArray(), Drupal\moduleHandler(), Drupal\service(), and AttachedAssetsInterface\setSettings().

Here is the call graph for this function:

getJsSettingsAssets ( AttachedAssetsInterface  $assets)
protected

Returns the JavaScript settings assets for this response's libraries.

Gathers all drupalSettings from all libraries in the attached assets collection and merges them.

Parameters
\Drupal\Core\Asset\AttachedAssetsInterface$assetsThe assets attached to the current response.
Returns
array A (possibly optimized) collection of JavaScript assets.

References AssetResolver\getLibrariesToLoad(), and NestedArray\mergeDeepArray().

Referenced by AssetResolver\getJsAssets().

Here is the call graph for this function:

Here is the caller graph for this function:

getLibrariesToLoad ( AttachedAssetsInterface  $assets)
protected

Returns the libraries that need to be loaded.

For example, with core/a depending on core/c and core/b on core/d:

$assets = new AttachedAssets();
$assets->setLibraries(['core/a', 'core/b', 'core/c']);
$assets->setAlreadyLoadedLibraries(['core/c']);
$resolver->getLibrariesToLoad($assets) === ['core/a', 'core/b', 'core/d']
Parameters
\Drupal\Core\Asset\AttachedAssetsInterface$assetsThe assets attached to the current response.
Returns
string[] A list of libraries and their dependencies, in the order they should be loaded, excluding any libraries that have already been loaded.

References AttachedAssetsInterface\getAlreadyLoadedLibraries(), and AttachedAssetsInterface\getLibraries().

Referenced by AssetResolver\getCssAssets(), AssetResolver\getJsAssets(), and AssetResolver\getJsSettingsAssets().

Here is the call graph for this function:

Here is the caller graph for this function:

static sort (   $a,
  $b 
)
static

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.

Parameters
$aFirst item for comparison. The compared items should be associative arrays of member items.
$bSecond item for comparison.
Returns
int

The documentation for this class was generated from the following file: