Thursday, September 22, 2011

Hook_Block() in Drupal with Example

function common_block($op = 'list', $delta = 0, $edit = array()) {

  /* List Block section in Admin Panel */
  if ($op == 'list') {
    $blocks[1] = array(
      'info' => t('testing information to show ...'),
      'weight' => 0,
      'status' => 1,
      'region' => 'dashboard_left',
    );
    $blocks[0]['info'] = t('Mano Content');
   
    return $blocks;
  }

 /* View section - once we display this region */
else if ($op == 'view') {
    switch ($delta) {
      case 0:
        // Your module will need to define this function to render the block.
        $block = array(
          'subject' => t('Title of block #1'),
          'content' => mymodule_display_block_1(),
        );
      break;
      case 1:
        // Your module will need to define this function to render the block.
        $block = array(
          'subject' => t('Title of block #2'),
          'content' => mymodule_display_block_2(),
        );
    }
    return $block;
  }
}

/* Function Call - for view section */
function mymodule_display_block_1(){
  $testing = "hook_block .. view section is working, delta 0, mano content";
  return $testing;
}

function mymodule_display_block_2(){
  $testing = "hook_block .. view section is working, delta 1, testing information to show";
  return $testing;
}

No comments:

Post a Comment

Followers