Drupal 6: Hide themes on the admin/build/themes page

If you’re like me, you manage a bunch of Drupal 6 sites AND you give site owners the ability to configure the theme.

The problem is that they also get the ability to choose another theme, and sometimes that’s not the best thing for the site (have you seen Pushbutton? Really?)

Sure, you could install something like system_perm to give more granular access over the theme management, but that might be a little more overhead than you want.

So, i wrote this quick snippet that you can add to a module, which will hide a list of unwanted themes (like the core themes you can’t delete without messing up your Drupal install royally).

Use at your own risk… but it’s really quite harmless. Just change “mymodulename” to your module/theme/whatever and change the list of themes to your liking.

Enjoy 🙂

// [[START CODE]]

/**
* Implementation of hook_form_alter().
* TESTED / USED IN DRUPAL 6 ONLY
*
* Hide all listed themes to make the theme list more user friendly
* IE: We dont want to show themes that should not be used by our users
*/

function mymodulename_form_alter(&$form, $form_state, $form_id) {
// Normally a switch is used because you may want to alter more than
// one form and it is easy to add a new case for each form.

switch ($form_id) {
// This is our form ID.
case ‘system_themes_form’:

$themesToDisable = array(
‘bluemarine’,
‘chameleon’,
‘marvin’,
‘minnelli’,
‘pushbutton’,
);

foreach($themesToDisable as $theme) {
unset($form[$theme]);
unset($form[‘status’][‘#options’][$theme]);
unset($form[‘theme_default’][‘#options’][$theme]);

}

break;
}

}

// [[END OF CODE]]