Create a block

Basically all we need is hook_block_info() and hook_block_view() to create a block.

By using hook_block_info() we declare which blocks are avaialable in our module. As seen on admin/structure/block.

Hook_block_view() handles the rendering part of the block.


/**
 * Implements hook_block_info().
 */
function MY_CUSTOM_MODULE_block_info() {
  
  $blocks['MY_CUSTOM_BLOCK'] = array(
    'info' => t('My custom block title as shown on admin/structure/block'),
  );
 
  return $blocks;

}

/**
 * Implements hook_block_view().
 */
function MY_CUSTOM_MODULE_block_view($delta) {

  switch ($delta) {
  	case 'MY_CUSTOM_BLOCK' : 
      return array(
        'subject' => t('My custom block title as shown when the block is rendered.'),
        'content' => t('In this example we use some dummy text, but we can render forms, custom templates or theming functions when wanted.'), 
      ); 		
  	  break;
  }
  
}

By writing 20 lines of code one of the most powerfull building tools of Drupal can be created. When you want to render forms or complex content inside a block there are other block related articles available in the Drupal 7 block section of this site.