diff --git a/core/includes/assets.inc b/core/includes/assets.inc new file mode 100644 index 0000000..b11866e --- /dev/null +++ b/core/includes/assets.inc @@ -0,0 +1,36 @@ +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(); } /** @@ -4876,6 +4851,7 @@ function _drupal_bootstrap_code() { require_once DRUPAL_ROOT . '/core/includes/errors.inc'; require_once DRUPAL_ROOT . '/core/includes/schema.inc'; require_once DRUPAL_ROOT . '/core/includes/entity.inc'; + require_once DRUPAL_ROOT . '/core/includes/assets.inc'; // Load all enabled modules module_load_all(); diff --git a/core/includes/install.core.inc b/core/includes/install.core.inc index 17e2a66..37af94b 100644 --- a/core/includes/install.core.inc +++ b/core/includes/install.core.inc @@ -285,6 +285,7 @@ function install_begin_request(&$install_state) { include_once DRUPAL_ROOT . '/core/includes/module.inc'; include_once DRUPAL_ROOT . '/core/includes/session.inc'; require_once DRUPAL_ROOT . '/core/includes/entity.inc'; + require_once DRUPAL_ROOT . '/core/includes/assets.inc'; // Determine whether the configuration system is ready to operate. $install_state['config_verified'] = install_verify_config_directory(CONFIG_ACTIVE_DIRECTORY) && install_verify_config_directory(CONFIG_STAGING_DIRECTORY); diff --git a/core/lib/Drupal/Core/Assets/AssetCollectionFactory.php b/core/lib/Drupal/Core/Assets/AssetCollectionFactory.php new file mode 100644 index 0000000..43a35f7 --- /dev/null +++ b/core/lib/Drupal/Core/Assets/AssetCollectionFactory.php @@ -0,0 +1,55 @@ + 'Drupal\Core\Assets\CssAssetCollection'); + $asset_types += array('js' => 'Drupal\Core\Assets\JsAssetCollection'); + return $asset_types; + } + +} diff --git a/core/lib/Drupal/Core/Assets/AssetCollectionInterface.php b/core/lib/Drupal/Core/Assets/AssetCollectionInterface.php new file mode 100644 index 0000000..b578380 --- /dev/null +++ b/core/lib/Drupal/Core/Assets/AssetCollectionInterface.php @@ -0,0 +1,48 @@ +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); + } + +}