1 color.module color_save_configuration($theme_name, $theme_info, $palette)

Generates the necessary CSS and images based on a color palette.

Parameters

$theme_name: The theme machine name.

$theme_info: The theme info, as loaded by list_themes().

$palette: The color palette on which the images and CSS will be generated.

Return value

array|NULL: Returns an array of values to be saved in the theme configuration. If no color settings are necessary (such as when using the default color scheme), NULL is returned.

File

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

Code

function color_save_configuration($theme_name, $theme_info, $palette) {
  // Delete any old color files.
  $files = theme_get_setting('color.files', $theme_name);
  if ($files) {
    foreach ($files as $file) {
      @backdrop_unlink($file);
    }
  }
  if (isset($file) && $file = dirname($file)) {
    @backdrop_rmdir($file);
  }

  // Don't render the default colorscheme, use the standard theme instead.
  if (empty($palette) || implode(',', color_get_palette($theme_name, TRUE)) == implode(',', $palette)) {
    return NULL;
  }

  // Prepare target locations for generated files.
  $id = $theme_name . '-' . substr(hash('sha256', serialize($palette) . microtime()), 0, 8);
  $paths['color'] = 'public://color';
  $paths['target'] = $paths['color'] . '/' . $id;
  foreach ($paths as $path) {
    file_prepare_directory($path, FILE_CREATE_DIRECTORY);
  }
  $paths['target'] = $paths['target'] . '/';
  $paths['id'] = $id;
  $paths['source'] = backdrop_get_path('theme', $theme_name) . '/';
  $paths['files'] = $paths['map'] = array();

  // Rewrite theme stylesheets.
  $css = array();
  foreach ($theme_info['css'] as $stylesheet) {
    // Build a temporary array with CSS files.
    $files = array();
    $filename = _color_get_file_path($stylesheet, $theme_name);
    if (file_exists($filename)) {
      $files[] = $stylesheet;
    }

    foreach ($files as $file) {
      // Aggregate @imports recursively for each configured top level CSS file
      // without optimization. Aggregation and optimization will be
      // handled by backdrop_build_css_cache() only.
      $filename = _color_get_file_path($file, $theme_name);
      $theme = _color_get_theme_from_file($file, $theme_name);
      $paths['source'] = backdrop_get_path('theme', $theme) . '/';

      $style = backdrop_load_stylesheet($filename, FALSE);

      // Return the path to where this CSS file originated from, stripping
      // off the name of the file at the end of the path.
      $base = base_path() . dirname($filename) . '/';
      _backdrop_build_css_path(NULL, $base);

      // Prefix all paths within this CSS file, ignoring absolute paths.
      $style = preg_replace_callback('/url\([\'"]?(?![a-z]+:|\/+)([^\'")]+)[\'"]?\)/i', '_backdrop_build_css_path', $style);

      // Rewrite stylesheet with new colors.
      $style = _color_rewrite_stylesheet($theme_name, $theme_info, $paths, $palette, $style);
      $base_file = backdrop_basename($file);
      $css[] = $paths['target'] . $base_file;
      _color_save_stylesheet($paths['target'] . $base_file, $style, $paths);
    }
  }

  return array(
    'palette' => $palette,
    'stylesheets' => $css,
    'files' => $paths['files'],
  );
}