diff -u b/core/includes/common.inc b/core/includes/common.inc --- b/core/includes/common.inc +++ b/core/includes/common.inc @@ -3019,6 +3019,17 @@ * @see drupal_add_css() */ function drupal_get_css($css = NULL, $skip_alter = FALSE) { + $css = _drupal_get_css($css, $skip_alter); + // Render the HTML needed to load the CSS. + $styles = array( + '#type' => 'styles', + '#items' => $css, + ); + + return drupal_render($styles); +} + +function _drupal_get_css($css = NULL, $skip_alter = FALSE) { if (!isset($css)) { $css = drupal_add_css(); } @@ -3031,18 +3042,6 @@ // Sort CSS items, so that they appear in the correct order. uasort($css, 'drupal_sort_css_js'); - // Provide the page with information about the individual CSS files used, - // information not otherwise available when CSS aggregation is enabled. The - // setting is attached later in this function, but is set here, so that CSS - // files removed below are still considered "used" and prevented from being - // added in a later AJAX request. - // Skip if no files were added to the page or jQuery.extend() will overwrite - // the Drupal.settings.ajaxPageState.css object with an empty array. - if (!empty($css)) { - // Cast the array to an object to be on the safe side even if not empty. - $setting['ajaxPageState']['css'] = (object) array_fill_keys(array_keys($css), 1); - } - // Remove the overridden CSS files. Later CSS files override former ones. $previous_item = array(); foreach ($css as $key => $item) { @@ -3057,16 +3056,7 @@ } } - // 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); - } - - return drupal_render($styles); + return $css; } /** @@ -4221,14 +4211,6 @@ return ''; } - // Decide if we need to output something. - // If only ['ajaxPageState']['css'] exists assume nothing is added. - if (isset($javascript['settings']) && count($javascript) == 1 && count($javascript['settings']['data']) == 1) { - if (isset($javascript['settings']['data'][0]['ajaxPageState']['css']) && count($javascript['settings']['data'][0]['ajaxPageState']) == 1) { - return ''; - } - } - // Register all required libraries. $libraries_added = &drupal_static(__FUNCTION__, FALSE); if (!$libraries_added) { @@ -4305,6 +4287,19 @@ } unset($setting['ajaxPageState']['js']['settings']); + // Provide the page with information about the individual CSS files used, + // information not otherwise available when CSS aggregation is enabled. The + // setting is attached later in this function, but is set here, so that CSS + // files removed below are still considered "used" and prevented from being + // added in a later AJAX request. + // Skip if no files were added to the page or jQuery.extend() will overwrite + // the Drupal.settings.ajaxPageState.css object with an empty array. + $css = _drupal_get_css(NULL, $skip_alter); + if (!empty($css)) { + // Cast the array to an object to be on the safe side even if not empty. + $setting['ajaxPageState']['css'] = (object) array_fill_keys(array_keys($css), 1); + } + $items['settings']['data'][] = $setting; $items['settings']['data'] = drupal_array_merge_deep_array($items['settings']['data']); }