Module with multiple Blocks in multiple files I've created a module which creates 2 blocks.

function my_module_block_info() {

  $blocks['blockA'] = array(
    'info' =&gt; t('blockA'),
    'cache' =&gt; DRUPAL_CACHE_PER_ROLE,
  );

  $blocks['blockB'] = array(
    'info' =&gt; t('blockB'),
    'cache' =&gt; DRUPAL_CACHE_PER_ROLE,
  );
  return $blocks;
}

function my_module_block_view($delta = '') {
  switch ($delta) {
    case 'blockA':
      $block['subject'] = t('subjectA');
      if (user_access('access content')) {
          $block['content'] = 'HelloA';
      }
      return $block;
      break;

    case 'blockB':
      $block['subject'] = t('subjectB');
      if (user_access('access content')) {
          $block['content'] = 'HelloB';
      }
      return $block;
      break;
}


Everything good so far. Here is my question:

I would like developers to create blocks using the same module (20 more blocks). How can I add a new block with its view without modifying the my_module.module? Is there a way to extend and include .php files that declare other blocks? So, instead of having a huge my_module.module file, I can have multiples .php files (one for each block).

Thank you in advance
* Method 1 - all blocks in separate file *

You can implement hook_hook_info() in your .modules file like this:

function hook_hook_info()
{
  $hooks['block_info']['group'] = 'block';
  $hooks['block_view']['group'] = 'block';

  return $hooks;
}


This tells the system that when hook_block_info() and/or hook_block_view() are invoked, any [MODULE].block.inc files should be loaded. So you can then put these two hooks into [MODULE].block.inc, keeping your block code in a separate file altogether.

* Method 2 - different file for each block *

You can add module_load_include() to include files for each block. To do this, in hook_block_view() you can do the following:

function hook_block_view($delta = '')
{
  if($delta == 'block1')
  {
    module_load_include('inc', 'MODULENAME', 'MODULENAME.block1');
  }
  elseif($delta == 'block2')
  {
    module_load_include('inc', 'MODULENAME', 'MODULENAME.block2');
  }
}


With this code, you can now put block1 in MODULENAME.block1.inc and block2 in MODULENAME.block2.inc. Note that MODULNAME should be the actual name of your module, though technically the module name isn't required, it's just a good practice.