Tuesday, August 23, 2011

Creation Of Drupal Module

Hello Friend,

I am back with new topic. This time I bring HOW TO CREATE DRUPAL custom module.

For creation of Drupal Module mailny we need two files first is .info and second is .module file.

Create a exapmle.info in your example folder. You may do so by using a notepad or any text editors. Copy the codes below

About example.info file

    ;$Id$

name = Test
description = Hello Kunal.
datestamp = "1202913006"

Description –

name (required)

The human readable name can now be set independently from the internal "machine" readable name. This imposes fewer restrictions on the allowed characters.

description (recommended)

A short description. This description is displayed on the module instll

core (required)

From 6.x onward, all .info files for modules and themes must indicate what major version of Drupal core they are compatible with.

Creation of .module

 
function example_help($section) {
  switch ($section) {
    case 'admin/modules#description':
      return t('This module implements an example form.');
  }
}
 
function example_menu($may_cache) {
  $items = array();
  if ($may_cache) {
    $items[] = array(
      'path' => 'example',
      'title' => t('Example'),
      'callback' => 'example_page',
      'access' => TRUE,
      'type' => MENU_CALLBACK
    );
  }
  return $items;
}
 
function example_page() {
  return drupal_get_form('example_page_form');
}
 
function example_page_form() {
  $form['fullname'] = array(
    '#type' => 'textfield',
    '#title' => t('Enter your full name'),
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
  );
  return $form;
}
 
function example_page_form_submit($form_id, $form_values) {
  $message = 'You have submitted the ' . $form_id . ' form which contains the following data:
' . print_r($form_values,true) . '
';
  drupal_set_message(t($message));
}
 
?>
 
After That Put your module inside examplesite/sites/all/modules/{your example  module}.
And Install Your module and make changes as yor wish. 
In my next post I will give you how to make install and unistall module and database access.

No comments:

Post a Comment