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