drupal_get_css

Versions
mediamosa-21
drupal_get_css($css = NULL)

Returns a themed representation of all stylesheets that should be attached to the page.

It loads the CSS in order, with 'module' first, then 'theme' afterwards. This ensures proper cascading of styles so themes can easily override module styles through CSS selectors.

Themes may replace module-defined CSS files by adding a stylesheet with the same filename. For example, themes/garland/system-menus.css would replace modules/system/system-menus.css. This allows themes to override complete CSS files, rather than specific selectors, when necessary.

If the original CSS file is being overridden by a theme, the theme is responsible for supplying an accompanying RTL CSS file to replace the module's.

Parameters

$css (optional) An array of CSS files. If no array is provided, the default stylesheets array is used instead.

Return value

A string of XHTML CSS tags.

▾ 3 functions call drupal_get_css()

template_process_html in includes/theme.inc
Process variables for html.tpl.php
template_process_maintenance_page in includes/theme.inc
The variables array generated here is a mirror of template_process_html(). This processor will run its course when theme_maintenance_page() is invoked. It is also used in theme_install_page() and theme_update_page() to keep all the variables consistent.
_color_html_alter in modules/color/color.module
Callback for the theme to alter the resources used.

Code

includes/common.inc, line 2729

<?php
function drupal_get_css($css = NULL) {
  if (!isset($css)) {
    $css = drupal_add_css();
  }

  // Allow modules to alter the CSS items.
  drupal_alter('css', $css);

  // Sort CSS items according to their weights.
  uasort($css, 'drupal_sort_weight');

  // Remove the overridden CSS files. Later CSS files override former ones.
  $previous_item = array();
  foreach ($css as $key => $item) {
    if ($item['type'] == 'file') {
      $basename = 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;
    }
  }

  // Render the HTML needed to load the CSS.
  $styles = array(
    '#type' => 'styles',
    '#items' => $css,
  );
  return drupal_render($styles);
}
?>