1 color.module color_css_alter(&$css)

Implements hook_css_alter().

Replaces style sheets with color-altered style sheets.

File

core/modules/color/color.module, line 172
Allows users to change the color scheme of themes.

Code

function color_css_alter(&$css) {
  global $theme_key;
  $themes = list_themes();

  $preview_theme = _color_preview_theme();
  if ($preview_theme) {
    // Convert stylesheets for the preview.
    $theme_info = color_get_info($preview_theme);
    if ($theme_info) {
      $theme_path = backdrop_get_path('theme', $preview_theme);
      if (isset($_SESSION['color'][$theme_key])) {
        $preview_data = $_SESSION['color'][$theme_key];
        $paths = array(
          'source' => backdrop_get_path('theme', $preview_theme) . '/',
          'map' => array(),
        );
        foreach ($theme_info['css'] as $file) {
          $stylesheet = file_get_contents($theme_path . '/' . $file);
          _backdrop_build_css_path(NULL, base_path() . dirname($paths['source'] . $file) . '/');
          $stylesheet = preg_replace_callback('/url\([\'"]?(?![a-z]+:|\/+)([^\'")]+)[\'"]?\)/i', '_backdrop_build_css_path', $stylesheet);

          $stylesheet = _color_rewrite_stylesheet($preview_theme, $theme_info, $paths, $preview_data['palette'], $stylesheet);
          foreach ($css as $path => $data) {
            if (backdrop_basename($path) == backdrop_basename($file)) {
              $css[$path]['type'] = 'inline';
              $css[$path]['preprocess'] = 'false';
              $css[$path]['data'] = $stylesheet;
              break;
            }
          }
        }
      }
    }
  }
  if (!isset($preview_data)) {
    // Override stylesheets.
    $color_paths = theme_get_setting('color.stylesheets');

    if (!empty($color_paths)) {
      foreach ($themes[$theme_key]->stylesheets['all'] as $base_filename => $old_path) {
        // Loop over the path array with recolored CSS files to find matching
        // paths which could replace the non-recolored paths.
        foreach ($color_paths as $color_path) {
          // Color module currently requires unique file names to be used,
          // which allows us to compare different file paths.
          if (backdrop_basename($old_path) == backdrop_basename($color_path)) {
            // Replace the path to the new css file.
            // This keeps the order of the stylesheets intact.
            $css[$old_path]['data'] = $color_path;
          }
        }
      }
    }
  }
}