AssetResolverInterface.php 3.3 KB

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