I'm writing a security module to allow enabling of certain modules for a multisite Drupal setup. Right now, we can disable the Modules form easily using the following snippet.
We would like to set the form elements to readonly and then enable the ability to enable/disable only a subset.
function disable_form_fields_form_alter(&$form, $form_state, $form_id) {
//get handle on drupal user var
global $user;
//if we are uid == 1 then we can edit this stuff...
if($user->uid !=1 && variable_get('osu_update_lockdown',1)==1){
if ($form_id == 'system_modules'){
//find all the modules not disabled
$modules_to_disabled = array_diff_key($form['status']['#options'], array_flip($form['status']['#disabled_modules']));
//for each not in our disabled list lets add it in
foreach($modules_to_disabled as $name => $value){
$form['status']['#disabled_modules'][] = $name;
}
//disable non-checked boxes
foreach($form['status']['#options'] as $key=>$val){
$form['status']['#process']['system_modules_disable'][0][]=$key;
}
//disable checked boxes
foreach($form['status']['#default_value'] as $key=>$val){
$form['status']['#process']['system_modules_disable'][0][]=$val;
}
unset($form['buttons']['submit']);
}
}
}