Disable Drupal Block Form

I often use the Context module for managing the block on sites. This is great, but then you have some settings in Context and some settings in the core Blocks config form. That can quickly become messy, so I wanted to find a way to “disable” the Blocks config so that users have to trely on Context. Actually, its just a few form_alter hooks to modify the forms in question. I usually just drop these into a custom module (or feature) when I want to lock things down.

<?php
/**
* Implements hook_form_alter()
* Hide the block page for the default theme
*/
function MYMODULE_form_block_admin_display_form_alter(&$form, &$form_state) {
  if (
$form['edited_theme']['#value'] == variable_get('theme_default', '')) {
   
// Set notice that we are using context to set blocks
   
$form['description'] = array(
     
'#markup' => '<h3>The blocks for the default theme are set using the <a href="/admin/structure/context">Context module</a>.</h3>',
     
'#weight' => -100,
    );
   
// Remove the block regions to clear the table
   
$form['block_regions']['#value'] = array(-1 => -1);
   
// Remove the region select options
   
foreach ($form['blocks'] as $block => $setting) {
      unset(
$form['blocks'][$block]['region']);
    }
   
// Remove the save button
   
unset($form['actions']);
  }
}

/**
* Implements hook_form_alter()
* Modify the block configure page to hide options
*/
function MYMODULE_form_block_admin_configure_alter(&$form, &$form_state) {
 
// Remove the region select for default theme
 
$form['regions']['#type'] = 'hidden';
 
// Reorder the form elements
 
$form['settings']['#weight'] = -10;
 
$form['cache']['#weight'] = 0;
 
// @TODO: Determine which if any of the visibility settings need to be hidden
}
?>