1

Is there a way to programmatically change the color scheme, set by the color module, for a certain theme in Drupal 6 (in PHP or using drush)? For example, I can change Garland's color scheme from the UI: set Garland color scheme

but I want to do it programatically.

2
  • What do you mean by setting the color scheme? Changing the colors of what?
    – herci
    Commented Aug 12, 2015 at 14:01
  • I mean it in regards to the color module. Edited the post to make it more clear.
    – dramzy
    Commented Aug 12, 2015 at 14:03

2 Answers 2

1

No - this is not possible in 6.x due to how color is intended to work. Its meant to be a simple way to change a very basic theme, not for advanced users. In 6.x, when you change your color settings, it is doing the following:

  • Replaces hexidecimal colour values in CSS files
  • Creates sliced images with the new colours for use as CSS background images
  • Copies unchanged images without alterations

This creates a dump of 'color files' that looks like this in your files directory (for the Garland theme)

bg-bar-white.png
bg-bar.png
bg-content-left.png
bg-content-right.png
...
style.css

It also creates a random number for the folder each time, so the folder is getting deleted and recreated each time you save the changes.

All of this is to make it easier for novice users to change their colors, with I assume the understanding that if users could configure their own CSS and theme in code, they wouldn't be using the color module to begin with. This approach is also confirmed here on D.O by Jeff Burnz

Currently there is no way in Drupal core to export your custom color scheme to file, i.e. no way to capture the configuration

Conversely, there is no way to import an existing dump of colors files into your site.

2
  • 3
    If you can change it through the UI, you can change it through code (at the end of the day they're one and the same thing). You can't import/export config, but if you want to programatically change the colours, you just need to follow the code in color_scheme_form_submit()
    – Clive
    Commented Aug 12, 2015 at 14:29
  • ... but you would re-create those files every time. May be bad, might be okay. Depending on case.
    – user18099
    Commented Jun 2, 2017 at 12:55
0

As per @clive's suggestion, looking at what color_sheme_form_submit() is doing:

_submit() will delete previous files listed in variable color_garland_files. But renaming the public files folder color/garland-dda79d31 to color/garland-RED will give you a permanent copy of that folder full of garland color files.

(Let color module generate that folder for you -- make a permanent copy)

Inside a "good hook" (I use _page_alter()) ... you can dynamically, temporarily over-write the $conf array (full of variable_get() variables for this current page call:

function modulename_ctools_render_alter() {
 // look at all the variables
 global $conf;
 kpr($conf);
 // look at the one we need
 $RED = variable_get('color_garland_stylesheets');
 // this, we will re-use:
 echo var_export($RED);
}

... will show you a PHP-formed array of said variable. Over-write it.

// this is how they look
#$STYLES = variable_get('color_garland_stylesheets');
#echo var_export($STYLES);
// over-write
$conf['color_garland_stylesheets'] = array(
    0 => 'public://color/garland-RED/style.css',
    1 => 'public://color/garland-RED/style-rtl.css',
  );

That was sufficient for me. All files in that folder can keep their filenames. All .css stays and works.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.