diff --git a/core/includes/common.inc b/core/includes/common.inc index aea8529..5ec87db 100644 --- a/core/includes/common.inc +++ b/core/includes/common.inc @@ -2687,43 +2687,18 @@ function drupal_add_css($data = NULL, $options = NULL) { * * @see drupal_add_css() */ -function drupal_get_css($css = NULL, $skip_alter = FALSE) { - if (!isset($css)) { - $css = drupal_add_css(); - } +function drupal_get_css($css = NULL, $skip_alter = FALSE, $group = NULL) { + $styles = drupal_container()->get('css_asset_manager'); + $styles->set($css, $group); // Allow modules and themes to alter the CSS items. if (!$skip_alter) { - drupal_alter('css', $css); - } - - // Sort CSS items, so that they appear in the correct order. - uasort($css, 'drupal_sort_css_js'); - - // Remove the overridden CSS files. Later CSS files override former ones. - $previous_item = array(); - foreach ($css as $key => $item) { - if ($item['type'] == 'file') { - // If defined, force a unique basename for this file. - $basename = isset($item['basename']) ? $item['basename'] : drupal_basename($item['data']); - if (isset($previous_item[$basename])) { - // Remove the previous item that shared the same base name. - unset($css[$previous_item[$basename]]); - } - $previous_item[$basename] = $key; - } + drupal_alter('css', $styles->assets); } - // Render the HTML needed to load the CSS. - $styles = array( - '#type' => 'styles', - '#items' => $css, - ); - if (!empty($setting)) { - $styles['#attached']['js'][] = array('type' => 'setting', 'data' => $setting); - } + $styles->sort(); - return drupal_render($styles); + return $styles->render(); } /** diff --git a/core/lib/Drupal/Core/Asset/AssetManager.php b/core/lib/Drupal/Core/Asset/AssetManager.php new file mode 100644 index 0000000..14e3736 --- /dev/null +++ b/core/lib/Drupal/Core/Asset/AssetManager.php @@ -0,0 +1,51 @@ + 'Drupal\Core\Asset\CssAssetManager'); + $asset_types += array('js' => 'Drupal\Core\Asset\JsAssetManager'); + return $asset_types; + } + +} diff --git a/core/lib/Drupal/Core/Asset/CssAssetManager.php b/core/lib/Drupal/Core/Asset/CssAssetManager.php new file mode 100644 index 0000000..29a5963 --- /dev/null +++ b/core/lib/Drupal/Core/Asset/CssAssetManager.php @@ -0,0 +1,84 @@ +assets; + } + foreach ($this->assets as $file) { + if (isset($file['group']) && $file['group'] == $group) { + $assets[] = $file; + } + } + return $assets; + } + + /** + * Implements Drupal\Core\Assets\AssetCollectionInterface::set(). + */ + function set($css = array(), $group = NULL) { + if (empty($css)) { + $this->assets = drupal_add_css(); + if (!empty($group) || $group === 0) { + $this->assets = $this->get($group); + } + } + else { + $this->assets = $css; + } + } + + /** + * Implements Drupal\Core\Assets\AssetCollectionInterface::set(). + */ + function sort() { + // Sort CSS items, so that they appear in the correct order. + uasort($this->assets, 'drupal_sort_css_js'); + + // Remove the overridden CSS files. Later CSS files override former ones. + $previous_item = array(); + foreach ($this->assets as $key => $item) { + if ($item['type'] == 'file') { + // If defined, force a unique basename for this file. + $basename = isset($item['basename']) ? $item['basename'] : drupal_basename($item['data']); + if (isset($previous_item[$basename])) { + // Remove the previous item that shared the same base name. + unset($this->assets[$previous_item[$basename]]); + } + $previous_item[$basename] = $key; + } + } + } + + /** + * Implements Drupal\Core\Assets\AssetCollectionInterface::set(). + */ + function render() { + // Render the HTML needed to load the CSS. + $styles = array( + '#type' => 'styles', + '#items' => $this->assets, + ); + return drupal_render($styles); + } + +} diff --git a/core/lib/Drupal/Core/CoreBundle.php b/core/lib/Drupal/Core/CoreBundle.php index 4dca804..0cd4a63 100644 --- a/core/lib/Drupal/Core/CoreBundle.php +++ b/core/lib/Drupal/Core/CoreBundle.php @@ -52,6 +52,14 @@ class CoreBundle extends Bundle ->setFactoryClass('Drupal\Core\Database\Database') ->setFactoryMethod('getConnection') ->addArgument('slave'); + $container->register('css_asset_manager', 'Drupal\Core\Asset\CssAssetManager') + ->setFactoryClass('Drupal\Core\Asset\AssetManagerFactory') + ->setFactoryMethod('get') + ->addArgument('css'); + /*$container->register('js_asset_manager', 'Drupal\Core\Assets\CssAssetCollection') + ->setFactoryClass('Drupal\Core\Assets\AssetCollectionFactory') + ->setFactoryMethod('get') + ->addArgument('js');*/ $container->register('typed_data', 'Drupal\Core\TypedData\TypedDataManager'); // @todo Replace below lines with the commented out block below it when it's