Sunday, March 13, 2011

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

3 comments:

  1. My ѕpousе and I abѕоlutely love your
    blog аnd find almost all of youг pοst's to be exactly what I'm lοoκing foг.
    Do you offer gueѕt ωriteгs to
    wrіte content to ѕuіt yοuг nеeds?
    Ι ωouldn't mind producing a post or elaborating on a few of the subjects you write in relation to here. Again, awesome website!

    Feel free to surf to my web site weight loss supplements

    ReplyDelete
  2. I thіnk thіѕ іs one of the most vіtal
    info foг me. And i'm glad reading your article. But want to remark on few general things, The web site style is great, the articles is really excellent : D. Good job, cheers

    Check out my webpage ... credit card debt relief

    ReplyDelete
  3. Great gooԁs from you, man. I've be aware your stuff prior to and you are simply too fantastic. I really like what you have got here, certainly like what you'ге statіng anԁ the way by which you assert it.
    You're making it entertaining and you continue to care for to keep it sensible. I cant wait to learn much more from you. That is actually a tremendous website.

    Here is my website :: bet365

    ReplyDelete