3 namespace Drupal\Core\Asset;
6 * Resolves asset libraries into concrete CSS and JavaScript assets.
8 * Given an attached assets collection (to be loaded for the current response),
9 * the asset resolver can resolve those asset libraries into a list of concrete
10 * CSS and JavaScript assets.
12 * In other words: this allows developers to translate Drupal's asset
13 * abstraction (asset libraries) into concrete assets.
15 * @see \Drupal\Core\Asset\AttachedAssetsInterface
16 * @see \Drupal\Core\Asset\LibraryDependencyResolverInterface
18 interface AssetResolverInterface {
21 * Returns the CSS assets for the current response's libraries.
23 * It returns the CSS assets in order, according to the SMACSS categories
24 * specified in the assets' weights:
30 * @see https://www.drupal.org/node/1887918#separate-concerns
31 * This ensures proper cascading of styles so themes can easily override
32 * module styles through CSS selectors.
34 * Themes may replace module-defined CSS files by adding a stylesheet with the
35 * same filename. For example, themes/bartik/system-menus.css would replace
36 * modules/system/system-menus.css. This allows themes to override complete
37 * CSS files, rather than specific selectors, when necessary.
39 * Also invokes hook_css_alter(), to allow CSS assets to be altered.
41 * @param \Drupal\Core\Asset\AttachedAssetsInterface $assets
42 * The assets attached to the current response.
43 * @param bool $optimize
44 * Whether to apply the CSS asset collection optimizer, to return an
45 * optimized CSS asset collection rather than an unoptimized one.
48 * A (possibly optimized) collection of CSS assets.
50 public function getCssAssets(AttachedAssetsInterface $assets, $optimize);
53 * Returns the JavaScript assets for the current response's libraries.
55 * References to JavaScript files are placed in a certain order: first, all
56 * 'core' files, then all 'module' and finally all 'theme' JavaScript files
57 * are added to the page. Then, all settings are output, followed by 'inline'
58 * JavaScript code. If running update.php, all preprocessing is disabled.
60 * Note that hook_js_alter(&$javascript) is called during this function call
61 * to allow alterations of the JavaScript during its presentation. The correct
62 * way to add JavaScript during hook_js_alter() is to add another element to
63 * the $javascript array, deriving from drupal_js_defaults(). See
64 * locale_js_alter() for an example of this.
66 * @param \Drupal\Core\Asset\AttachedAssetsInterface $assets
67 * The assets attached to the current response.
68 * Note that this object is modified to reflect the final JavaScript
70 * @param bool $optimize
71 * Whether to apply the JavaScript asset collection optimizer, to return
72 * optimized JavaScript asset collections rather than an unoptimized ones.
75 * A nested array containing 2 values:
76 * - at index zero: the (possibly optimized) collection of JavaScript assets
77 * for the top of the page
78 * - at index one: the (possibly optimized) collection of JavaScript assets
79 * for the bottom of the page
81 public function getJsAssets(AttachedAssetsInterface $assets, $optimize);