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:
but I want to do it programatically.
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:
but I want to do it programatically.
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:
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.
color_scheme_form_submit()
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.