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
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