function zenophile_midnight_zenophile_alter in Zenophile 6.2
Same name and namespace in other branches
- 7 zenophile_midnight/zenophile_midnight.module \zenophile_midnight_zenophile_alter()
Implementation of hook_zenophile_alter() (a Zenophile hook).
Add the CSS files and add the lines the .info file. We have the Views and Ubercart CSS in a separate file so that site builders who don't use these can easily remove them by commenting out its line in the .info file.
This is Zenophile's one and only hook. It lets you modify the list of files that Zenophile will use to build the theme. Note that the order that these hooks are called is relevant; you should take care not to modify the info for a file which isn't in the $file array yet, or your data will be clobbered when another hook adds it. If necessary, use a hook_install() to modify your module's weight value in {system} (see Zenophile's own hook_install() for an example).
Parameters
$files: An associative array of files which will be copied or created for the new theme. Your hook implementation should receive this value by reference and modify it. Your implementation shouldn't return anything. $files will be an associative array with the key being the name of the file relative to the new theme's directory, and the value being an associative array with the following keys: 'from' - The path to the source file, if this file is being copied; a blank string, if this should be a new file. Ignored if the 'type' value is 'dir'. 'type' - 'file' or 'dir' depending on whether a file or directory should be created/copied. Note that directories are *never* copied; if you wish to completely copy a directory, you need to add all of its child files and directories to $files too. The _zenophile_populate_files() function can help with this; check out its definition in zenophile.module and how it is used below. 'repl' - an array of regular expression replacements to run on the text of the file, with the key being the pattern and the value being the replacement. This is ignored, of course, if 'type' === 'dir'. 'weight' - A weight value which lets you set the order that the items in the $files directory are processed. In actuality, this probably doesn't matter, but I added this functionality for some reason, so there must have been a good reason at some point in time.
$info: An associative array of info about the theme, with the following keys and values; 't_name' - The system name of the theme. 't_dir' - The directory where the theme will reside. 'parent' - The parent theme system name. 'parent_dir' - The directory where the parent theme resides. 'zen_dir' - The directory where Zen resides. 'form_values' - The submitted form values. use this to check the values of the form elements you added earlier. See below for an example.
File
- zenophile_midnight/
zenophile_midnight.module, line 100 - Aid to create light-on-dark Zen-based themes with Zenophile.
Code
function zenophile_midnight_zenophile_alter(&$files, $info) {
if ($info['form_values']['midnight']) {
$css_dir = $info['form_values']['zen_info']['vers_float'] >= 2 ? 'css/' : '';
$weight = 60990;
$my_dir = drupal_get_path('module', 'zenophile_midnight');
$files[$css_dir . 'zen_midnight.css'] = array(
'from' => $my_dir . '/css/zen_midnight.css',
'type' => 'file',
'repl' => array(
'~^/* $Id.+$~' => '/* $I' . 'd$ */',
),
'weight' => $weight += 10,
);
$files[$css_dir . 'zen_midnight_views.css'] = array(
'from' => $my_dir . '/css/zen_midnight_views.css',
'type' => 'file',
'repl' => array(
'~^/* $Id.+$~' => '/* $I' . 'd$ */',
),
'weight' => $weight += 10,
);
$files[$css_dir . 'zen_midnight_ubercart.css'] = array(
'from' => $my_dir . '/css/zen_midnight_ubercart.css',
'type' => 'file',
'repl' => array(
'~^/* $Id.+$~' => '/* $I' . 'd$ */',
),
'weight' => $weight += 10,
);
// Just in case the parent theme doesn't have an image directory defined
// already
if (!isset($files['images'])) {
$files['images'] = array(
'type' => 'dir',
'weight' => $weight += 10,
);
}
// Add my images to $files
foreach (_zenophile_populate_files($my_dir, 'images') as $file => $type) {
$files[$file] = array(
'from' => "{$my_dir}/{$file}",
'type' => $type,
'repl' => array(),
'weight' => $weight += 10,
);
}
// …but we actually want the logo image to go somewhere else
$files['logo.png'] = $files['images/logo.png'];
unset($files['images/logo.png']);
// …and likewise with the screenshot image
$files['screenshot.png'] = $files['images/screenshot.png'];
unset($files['images/screenshot.png']);
// Add the CSS files to the .info file
$files[$info['t_name'] . '.info']['repl']['/print\\.css$/m'] = "print.css\n\n ; Add Zen Midnight stylesheets for dark-on-light color scheme\nstylesheets[all][] = {$css_dir}zen_midnight.css\nstylesheets[all][] = {$css_dir}zen_midnight_views.css\nstylesheets[all][] = {$css_dir}zen_midnight_ubercart.css\n";
}
}