You are here

function drupal_load_stylesheet in Drupal 7

Same name and namespace in other branches
  1. 6 includes/common.inc \drupal_load_stylesheet()

Loads the stylesheet and resolves all @import commands.

Loads a stylesheet and replaces @import commands with the contents of the imported file. Use this instead of file_get_contents when processing stylesheets.

The returned contents are compressed removing white space and comments only when CSS aggregation is enabled. This optimization will not apply for color.module enabled themes with CSS aggregation turned off.

Parameters

$file: Name of the stylesheet to be processed.

$optimize: Defines if CSS contents should be compressed or not.

$reset_basepath: Used internally to facilitate recursive resolution of @import commands.

Return value

Contents of the stylesheet, including any resolved @import commands.

4 calls to drupal_load_stylesheet()
CascadingStylesheetsUnitTest::testLoadCssBasic in modules/simpletest/tests/common.test
Tests basic CSS loading with and without optimization via drupal_load_stylesheet().
color_scheme_form_submit in modules/color/color.module
Form submission handler for color_scheme_form().
drupal_build_css_cache in includes/common.inc
Aggregates and optimizes CSS files into a cache file in the files directory.
_drupal_load_stylesheet in includes/common.inc
Loads stylesheets recursively and returns contents with corrected paths.

File

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

Code

function drupal_load_stylesheet($file, $optimize = NULL, $reset_basepath = TRUE) {

  // These statics are not cache variables, so we don't use drupal_static().
  static $_optimize, $basepath;
  if ($reset_basepath) {
    $basepath = '';
  }

  // Store the value of $optimize for preg_replace_callback with nested
  // @import loops.
  if (isset($optimize)) {
    $_optimize = $optimize;
  }

  // Stylesheets are relative one to each other. Start by adding a base path
  // prefix provided by the parent stylesheet (if necessary).
  if ($basepath && !file_uri_scheme($file)) {
    $file = $basepath . '/' . $file;
  }

  // Store the parent base path to restore it later.
  $parent_base_path = $basepath;

  // Set the current base path to process possible child imports.
  $basepath = dirname($file);

  // Load the CSS stylesheet. We suppress errors because themes may specify
  // stylesheets in their .info file that don't exist in the theme's path,
  // but are merely there to disable certain module CSS files.
  $content = '';
  if ($contents = @file_get_contents($file)) {

    // Return the processed stylesheet.
    $content = drupal_load_stylesheet_content($contents, $_optimize);
  }

  // Restore the parent base path as the file and its childen are processed.
  $basepath = $parent_base_path;
  return $content;
}