drupal Module development - Drupal 7 Basic module providing a custom block

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Example

custom_module.info

name = Custom Module
description = Creates a block containing a custom output.
core = 7.x

custom_module.module

/**
 * Initiates hook_block_info.
 *
 * Registers the block with Drupal.
 */
function custom_module_block_info() {
  $blocks = array();
    //Registers the machine name of the block.
  $blocks['custom_block'] = array(
      //Sets the human readable, administration name.
    'info' => t('My Custom Block'),
      //Tells Drupal not to cache this block.
      //Used if there is dynamic content.
    'cache' => DRUPAL_NO_CACHE,
  );
  return $blocks;
}

/**
 * Initiates hook_block_view().
 *
 * Sets the block title and content callback.
 */
function custom_module_block_view($delta = '') {
  $block = array();

  switch ($delta) {
      //Must be the machine name defined in the hook_block_info.
    case 'custom_block':
        //The blocks title.
      $block['subject'] = 'My custom block';
        //The string or function that will provide the content of the block.
      $block['content'] = custom_module_block_content(); 
      break;
  }

  return $block;
}

/**
 * Returns the content of the custom block.
 */
function custom_module_block_content() {
  $content = "This function only returns a string, but could do anything."

  return $content;
}


Got any drupal Question?