Sunday, March 13, 2011

Display 2 blocks besides each other in the main content in Drupal 7

Display 2 blocks besides each other in the main content


First Set the 2 blocks to display on the main content. Go to Structure->Blocks
Set the blocks to main content.

Now when you close the overlay. You will see 2 blocks on the main page.

Right click and view source. If your module has css file set you can change over there or you can change the css file in style.css of your theme.

Basically you now have to modify the css file to display to blocks besides each other rather than vertical position.

Right click and view source now find the id for your block and set the css as below.

#listtable, #td {
    border:1px solid black; width:200px
}
#tr.invisible td{border:0px;width:40px}

#breadcrumb {display: none;}

#deductible-custom-form{
float: right;
margin-top:75px;
display:block;
width: 200px;
position: relative;
}
#display-list{
/*border:0.5px solid black;
background-color:lightgrey;*/
height: auto;
position: 10;
width: 200px;
float: left;
}

#block-deductible-list{
/*border:0.5px solid black;
background-color:lightgrey;*/
display: block;
height: auto;
position: relative;
width: 200px;
float: left;
}

.region-content{
max-width:500px;
min-width:500px;
}

now you will also have to modify the region content to set the maximum and minimum region so that blocks dont fall over in vertical position.

In above I have set one block to float left and one to float right this sets my two blocks in same line.
float: right;


Simple Help Module in Drupal / Drupal 7

Simple Block Module in Drupal / Drupal 7

Create a simple module using the example on this link

http://harshal-techapps.blogspot.com/2011/03/simple-form-example-drupal-7-with.html

Then replace the deductible.module in that example with below.

This is the deductible.module
<?php
//;$Id$

/**
 * @file
 * Enables a single blog for an individual or multiple users.
 */
// After you learn Form API in Chapter 5, you'll be able to
// make these settings configurable.

function deductible_help($section) {
    switch ($section) {
        case 'admin/help#deductible':
            return t('This module stores deductible for given make an Model');
    }
}

function deductible_menu(){
   
    $items['deductible/list']=array(
    //    'title'=>'Calculate Deductible',
        'page callback'=>'drupal_get_form',
        'page arguments'=>array('display_list'),
        'file'=> 'list.inc',
        'access arguments' => array('administer user'),
    );
   
    $items['deductible/add_carrier']=array(
    //    'title'=>'Calculate Deductible',
        'page callback'=>'drupal_get_form',
        'page arguments'=>array('addcarrier_form'),
        'access arguments' => array('administer user'),
        'file'=> 'carrier.inc',
    //'type' => MENU_CALLBACK,
    );
   
    $items['deductible/calculate']=array(
    //    'title'=>'Calculate Deductible',
        'page callback'=>'drupal_get_form',
        'page arguments'=>array('deductible_custom_form'),
        'access arguments' => array('administer user'),
        'file'=> 'deductibleadd.inc',
//        'type' => MENU_CALLBACK,
    );



    //watchdog('Deductibe', '1', array(), WATCHDOG_DEBUG);
    $items['deductible/display_results'] = array(
    //    'title'=>'Calculate Deductible',
        'access arguments' => array('administer user'),
        'page callback' => 'display_results',
        'access callback' => TRUE,
    //'type' => MENU_CALLBACK,
    );
    $items['deductible/delete/%'] = array(
    //    'title'=>'Calculate Deductible',
        'access arguments' => array('administer user'),
        'page callback' => 'delete_item',
        'access callback' => TRUE,
        'page arguments' => array(0,1,2),
        'file'=> 'deductibledelete.inc',
    //'type' => MENU_LOCAL_TASK,
    );
    //watchdog('Deductibe', '2', array(), WATCHDOG_DEBUG);
    return $items;
}



/**
 * Implementation of hook_perm().
 */
function deductible_permission() {
  return array('administer user');
}

function display_results()
{
    $result = db_query("SELECT itemid,make,model,deductible FROM {Deductible}");
    $listitems=array();
    $bigitems = array();
    foreach ($result as $item) {
        watchdog('Deductibe', 'hi', array(), WATCHDOG_DEBUG);
        $listitems=array($item->make,
        $item->model,
        $item->deductible,
        l('Delete','deductible/delete/'.$item->itemid),
        l('Update','deductible/update/'.$item->itemid)
        );
        $bigitems[]=$listitems;
    }

    //   return print_r($bigitems);
    if (count($listitems) == 0)
    $make[] = array("No Models Entered Yet");
    else{
        watchdog('Deductibe', 'a', array(), WATCHDOG_DEBUG);
    }

    $link_to_add_form = l('Add More Models','deductible/calculate');
    $variable=array(
             'header' =>  array(t('Make'), t('Model'),t('Deductible'),t('Delete'),t('Update')),
             'rows'  =>  $bigitems,
             'attributes' => array(),
             'caption' => NULL,
             'colgroups' => NULL,
             'sticky' => NULL,
             'empty' => NULL,
    );
    // return print_r($items);
    return theme_table($variable).'<br/>'.$link_to_add_form;
}

function theme_deductible($form) {
    watchdog('Deductibe', 'abf', array(), WATCHDOG_DEBUG);
    $output = drupal_render($form['Title']);
    return $output;
}

function deductible_theme($existing, $type, $theme, $path) {
    return array(
    'deductible' => array(
      'arguments' => array('form' => NULL),
        'template' => 'deductible',   
        'render element' => 'form',   
      'file'=> 'deductibleadd.inc',   
    ),
    'list' => array(
      'arguments' => array('form' => NULL),
        'template' => 'list',   
        'render element' => 'form',       
          ),
      'carrier' => array(
      'arguments' => array('form' => NULL),
        'template' => 'carrier',   
        'render element' => 'form',       
          ),   
    );
}

function deductible_block_info() {
    $blocks = array();
    // The array key defines the $delta parameter used in all
    // other block hooks.
    $blocks['list'] = array(
       // The name of the block on the blocks administration page.
       'info' => t('List'),
        'file'=>'list.inc',
    );
    return $blocks;
}

function deductible_block_view($delta = '') {
 $block = array();
 switch ($delta) {
 case "list":
 $form = drupal_get_form('display_list');
 $block["content"] = $form;
 break;
 }
 return $block;
 }

function display_list(){
    $form = array();
    $path = drupal_get_path('module', 'Deductible');
    $form['#attached'] = array
    (
    'css' => array
    (
        'type' => 'file',
        'data' => $path . '/root.css',
    ),
    'js' => array
    (
        'type' => 'file',
        'data' => $path . '/root.js',
    ),
    );
    $form['#theme'] = 'list';
    return $form;
}






You can access the help module when you enable the Module from Modules menu on the top you See help link besides the module. Also on the top you will see Help Menu Once you click on the help menu you will see Calculate Deductible Module

Simple Block Module in Drupal 7

Simple Block Module in Drupal 7

Create a simple module using the example on this link

http://harshal-techapps.blogspot.com/2011/03/simple-form-example-drupal-7-with.html

Then replace the deductible.module in that example with below.

This is the deductible.module
<?php
//;$Id$

/**
 * @file
 * Enables a single blog for an individual or multiple users.
 */
// After you learn Form API in Chapter 5, you'll be able to
// make these settings configurable.

function deductible_help($section) {
    switch ($section) {
        case 'admin/help#deductible':
            return t('This module stores deductible for given make an Model');
    }
}

function deductible_menu(){
   
    $items['deductible/list']=array(
    //    'title'=>'Calculate Deductible',
        'page callback'=>'drupal_get_form',
        'page arguments'=>array('display_list'),
        'file'=> 'list.inc',
        'access arguments' => array('administer user'),
    );
   
    $items['deductible/add_carrier']=array(
    //    'title'=>'Calculate Deductible',
        'page callback'=>'drupal_get_form',
        'page arguments'=>array('addcarrier_form'),
        'access arguments' => array('administer user'),
        'file'=> 'carrier.inc',
    //'type' => MENU_CALLBACK,
    );
   
    $items['deductible/calculate']=array(
    //    'title'=>'Calculate Deductible',
        'page callback'=>'drupal_get_form',
        'page arguments'=>array('deductible_custom_form'),
        'access arguments' => array('administer user'),
        'file'=> 'deductibleadd.inc',
//        'type' => MENU_CALLBACK,
    );



    //watchdog('Deductibe', '1', array(), WATCHDOG_DEBUG);
    $items['deductible/display_results'] = array(
    //    'title'=>'Calculate Deductible',
        'access arguments' => array('administer user'),
        'page callback' => 'display_results',
        'access callback' => TRUE,
    //'type' => MENU_CALLBACK,
    );
    $items['deductible/delete/%'] = array(
    //    'title'=>'Calculate Deductible',
        'access arguments' => array('administer user'),
        'page callback' => 'delete_item',
        'access callback' => TRUE,
        'page arguments' => array(0,1,2),
        'file'=> 'deductibledelete.inc',
    //'type' => MENU_LOCAL_TASK,
    );
    //watchdog('Deductibe', '2', array(), WATCHDOG_DEBUG);
    return $items;
}



/**
 * Implementation of hook_perm().
 */
function deductible_permission() {
  return array('administer user');
}

function display_results()
{
    $result = db_query("SELECT itemid,make,model,deductible FROM {Deductible}");
    $listitems=array();
    $bigitems = array();
    foreach ($result as $item) {
        watchdog('Deductibe', 'hi', array(), WATCHDOG_DEBUG);
        $listitems=array($item->make,
        $item->model,
        $item->deductible,
        l('Delete','deductible/delete/'.$item->itemid),
        l('Update','deductible/update/'.$item->itemid)
        );
        $bigitems[]=$listitems;
    }

    //   return print_r($bigitems);
    if (count($listitems) == 0)
    $make[] = array("No Models Entered Yet");
    else{
        watchdog('Deductibe', 'a', array(), WATCHDOG_DEBUG);
    }

    $link_to_add_form = l('Add More Models','deductible/calculate');
    $variable=array(
             'header' =>  array(t('Make'), t('Model'),t('Deductible'),t('Delete'),t('Update')),
             'rows'  =>  $bigitems,
             'attributes' => array(),
             'caption' => NULL,
             'colgroups' => NULL,
             'sticky' => NULL,
             'empty' => NULL,
    );
    // return print_r($items);
    return theme_table($variable).'<br/>'.$link_to_add_form;
}

function theme_deductible($form) {
    watchdog('Deductibe', 'abf', array(), WATCHDOG_DEBUG);
    $output = drupal_render($form['Title']);
    return $output;
}

function deductible_theme($existing, $type, $theme, $path) {
    return array(
    'deductible' => array(
      'arguments' => array('form' => NULL),
        'template' => 'deductible',   
        'render element' => 'form',   
      'file'=> 'deductibleadd.inc',   
    ),
    'list' => array(
      'arguments' => array('form' => NULL),
        'template' => 'list',   
        'render element' => 'form',       
          ),
      'carrier' => array(
      'arguments' => array('form' => NULL),
        'template' => 'carrier',   
        'render element' => 'form',       
          ),   
    );
}

function deductible_block_info() {
    $blocks = array();
    // The array key defines the $delta parameter used in all
    // other block hooks.
    $blocks['list'] = array(
       // The name of the block on the blocks administration page.
       'info' => t('List'),
        'file'=>'list.inc',
    );
    return $blocks;
}

function deductible_block_view($delta = '') {
 $block = array();
 switch ($delta) {
 case "list":
 $form = drupal_get_form('display_list');
 $block["content"] = $form;
 break;
 }
 return $block;
 }

function display_list(){
    $form = array();
    $path = drupal_get_path('module', 'Deductible');
    $form['#attached'] = array
    (
    'css' => array
    (
        'type' => 'file',
        'data' => $path . '/root.css',
    ),
    'js' => array
    (
        'type' => 'file',
        'data' => $path . '/root.js',
    ),
    );
    $form['#theme'] = 'list';
    return $form;
}