2009-05-05 122 views
2

我正在編寫一個安全模塊,以允許爲多站點Drupal設置啓用某些模塊。現在,我們可以使用下面的代碼片段輕鬆禁用Modules表單。是否可以將模塊的複選框設置爲「只讀」?

我們希望將表單元素設置爲只讀,然後啓用僅啓用/禁用子集的功能。

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']); 

     } 
    } 
} 

回答

0

是的,你可以使用這個#attributes設置爲只讀:

'#attributes' => array('readonly' => 'readonly'), 

因此,對於您的形式是類似的東西:

$form['status']['#attributes'] = array('readonly' => 'readonly'); 

這將使您的形式只讀。

相關問題