Same name and namespace in other branches
  1. 6.x includes/common.inc \drupal_get_css()
  2. 7.x includes/common.inc \drupal_get_css()

Returns a themed representation of all stylesheets that should be attached to the page. It loads the CSS in order, with 'core' CSS first, then 'module' CSS, then 'theme' CSS files. This ensures proper cascading of styles for easy overriding in modules and themes.

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.

Related topics

5 calls to drupal_get_css()
chameleon_page in themes/chameleon/chameleon.theme
phptemplate_page in themes/engines/phptemplate/phptemplate.engine
Prepare the values passed to the theme_page function to be passed into a pluggable template engine. Uses the arg() function to generate a series of page template files suggestions based on the current path. If none are found, the default page.tpl.php…
theme_install_page in includes/theme.inc
theme_page in includes/theme.inc
Return an entire Drupal page displaying the supplied content.
_color_page_alter in modules/color/color.module
Callback for the theme to alter the resources used.

File

includes/common.inc, line 1602
Common functions that many Drupal modules will need to reference.

Code

function drupal_get_css($css = NULL) {
  $output = '';
  if (!isset($css)) {
    $css = drupal_add_css();
  }
  $preprocess_css = variable_get('preprocess_css', FALSE);
  $directory = file_directory_path();
  $is_writable = is_dir($directory) && is_writable($directory) && variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC) == FILE_DOWNLOADS_PUBLIC;
  foreach ($css as $media => $types) {

    // If CSS preprocessing is off, we still need to output the styles.
    // Additionally, go through any remaining styles if CSS preprocessing is on and output the non-cached ones.
    foreach ($types as $type => $files) {
      foreach ($types[$type] as $file => $preprocess) {
        if (!$preprocess || !($is_writable && $preprocess_css)) {

          // If a CSS file is not to be preprocessed and it's a module CSS file, it needs to *always* appear at the *top*,
          // regardless of whether preprocessing is on or off.
          if (!$preprocess && $type == 'module') {
            $no_module_preprocess .= '<style type="text/css" media="' . $media . '">@import "' . base_path() . $file . '";</style>' . "\n";
          }
          else {
            if (!$preprocess && $type == 'theme') {
              $no_theme_preprocess .= '<style type="text/css" media="' . $media . '">@import "' . base_path() . $file . '";</style>' . "\n";
            }
            else {
              $output .= '<style type="text/css" media="' . $media . '">@import "' . base_path() . $file . '";</style>' . "\n";
            }
          }
        }
      }
    }
    if ($is_writable && $preprocess_css) {
      $filename = md5(serialize($types)) . '.css';
      $preprocess_file = drupal_build_css_cache($types, $filename);
      $output .= '<style type="text/css" media="' . $media . '">@import "' . base_path() . $preprocess_file . '";</style>' . "\n";
    }
  }
  return $no_module_preprocess . $output . $no_theme_preprocess;
}