Do not forget to make your module blocks Configurable

 

We needed to perform some regression testing on a production server of a Drupal module.  The Drupal module output a block and we needed to display this block on a simple Testing page so as not to affect other parts of the site.  I uploaded my changed module and proceeded to configure the block so it would only appear on this specific page.  ERROR.  Total white screen of Drupal death.

As it turns out, in order to configure blocks that come from a module, the module needs to respond to the "configure" and "save" operations in the module_block hook.  My module was only written to repond to the "list" and "view" operations.  A quick copy-n-paste later, I was able to configure my module block to only appear on my testing page, and I was away.

 

 

function custom_module_block($op = 'list', $delta = 0, $edit = array()) {
  switch ($op) {
    case 'list':
      $blocks[0]['info'] = t('Custom Module);      
      $blocks[0]['cache'] = BLOCK_NO_CACHE;
      return $blocks;
    case 'configure':
      $box = array('format' => FILTER_FORMAT_DEFAULT);
      if ($delta) {
        $box = block_box_get($delta);
      }
      if (filter_access($box['format'])) {
        return block_box_form($box);
      }
      break;
    case 'save':
      block_box_save($edit, $delta);
      break;
    case 'view': default:
      switch ($delta) {
        case 0:
          $block['subject'] = t('');
        $block['content'] = student_app_status_contents();
          break;
      }
      $block['cache'] = BLOCK_NO_CACHE; 
      return $block;
  }
}

 

Comments

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options