際際滷

際際滷Share a Scribd company logo
Modules in Drupal 7 
Basics - introduction to Modules in drupal 7
intro 
Modules in drupal are used to extend and customize the drupal 
features and functionality. Its like a library / plugin in drupal 7. 
There are thousands of module available on the drupal.org 
community. One of most important and major section in drupal 
website development. Modules can be easily map with the system
Types of module 
 Core - with comes default in the drupal core. you will find it 
in root_dictory/modules. 
 Contributed - Developed by the contributor of the drupal 
community. developer need to install on the system if need. 
you can find it in root_diretory/sites/all/modules. 
 Custom - written by developer. to achieve this should 
technical skills includes php,drupal coding standard.you can 
find it in root_diretory/sites/all/modules
Modules file architecture 
.info - The information about the module file is called 
.info.There can be additional values, but these are the 
essentials. The syntax is a simple label equals value 
pairing. 
.inc - The functional code of section like views, admin , hooks 
methods can be derived at inc files [optional]. 
dependencies[ ] - If your module needs some other module to 
work. the module name you can mention in dependencies section.
Sample code mymodule.info file: 
name = Mymodule (Human-readable name of our module ) 
description = Shows functionalities of my website. (Describes 
what our module does in a sentence or two) 
core = 7.x 
; Require the core Help module and the contrib Views module to 
be enabled. 
dependencies[] = help 
dependencies[] = views
.module File 
The functional code of the module file is called .module. The 
.module file must have the same machine name as the .info 
file,which for both should be the same name as the folder they are 
in. 
Mostly contains the hooks and major part of the modules function 
declaration.
<?php 
/** 
* @file 
* Helps site builders and module developers investigate a site. 
*/ 
/** 
* Implements hook_form_alter() to show each form's identifier. 
*/ 
function mymodule_form_alter(&$form, &$form_state, $form_id) { 
$form['mymodule_display_form_id'] = array('#type' => 'item','#title' => t('Form ID'), 
'#markup' => $form_id,'#weight' => -100,); 
}
Configure option 
The configure directive, optional but highly recommended, lets 
you provide the path to your modules configuration page. Drupal 
uses this path to provide a link on the Modules administration 
page when the module is enabled. you have to mention in .info 
file. 
The following is an example of a configure directive from the 
core search module: 
configure = admin/config/search/settings
Module enable/disable/uninstall 
place your module on the root_directory/sites/all/module/module. 
Goto Admin Menu => modules. you can see all core and 
contributed modules.click on enabled option and save. if want 
disable uncheck the option and save for the same. Also any 
configuration and permission needed for the module you can see 
configure & permission link corresponding to the module name. 
To uninstall - Admin Menu => modules you will find uninstall 
tab on top right. check the list of module proceed uninstall. 
uninstall option will completely remove your physical datatables 
related to the modules.
Introduction And Basics of Modules in Drupal 7
Hooks 
The hooks allows in module do something before the it is get 
executed. Its almost like event listener whenever an action taken 
place in drupal like saving,editing,deleting comments, node, users 
the system invites all any module involved.Every hook is an 
opportunity for your module to take action in response to 
something Drupal is doing. Apptx around 250 hooks are there in 
drupal system. hook is the placeholder your module name will be 
replaced there.
Sample Code 
function mymodule_help($path, $arg) { 
if ($path == 'admin/structure') { 
return t('This site has stuff!'); 
} 
} 
Styling Your Module : Adding a CSS File 
you can all the css files needed for your module in .info file. 
stylesheets[all][] = mymodule.css
Thank U 
Dhinakaran M

More Related Content

Introduction And Basics of Modules in Drupal 7

  • 1. Modules in Drupal 7 Basics - introduction to Modules in drupal 7
  • 2. intro Modules in drupal are used to extend and customize the drupal features and functionality. Its like a library / plugin in drupal 7. There are thousands of module available on the drupal.org community. One of most important and major section in drupal website development. Modules can be easily map with the system
  • 3. Types of module Core - with comes default in the drupal core. you will find it in root_dictory/modules. Contributed - Developed by the contributor of the drupal community. developer need to install on the system if need. you can find it in root_diretory/sites/all/modules. Custom - written by developer. to achieve this should technical skills includes php,drupal coding standard.you can find it in root_diretory/sites/all/modules
  • 4. Modules file architecture .info - The information about the module file is called .info.There can be additional values, but these are the essentials. The syntax is a simple label equals value pairing. .inc - The functional code of section like views, admin , hooks methods can be derived at inc files [optional]. dependencies[ ] - If your module needs some other module to work. the module name you can mention in dependencies section.
  • 5. Sample code mymodule.info file: name = Mymodule (Human-readable name of our module ) description = Shows functionalities of my website. (Describes what our module does in a sentence or two) core = 7.x ; Require the core Help module and the contrib Views module to be enabled. dependencies[] = help dependencies[] = views
  • 6. .module File The functional code of the module file is called .module. The .module file must have the same machine name as the .info file,which for both should be the same name as the folder they are in. Mostly contains the hooks and major part of the modules function declaration.
  • 7. <?php /** * @file * Helps site builders and module developers investigate a site. */ /** * Implements hook_form_alter() to show each form's identifier. */ function mymodule_form_alter(&$form, &$form_state, $form_id) { $form['mymodule_display_form_id'] = array('#type' => 'item','#title' => t('Form ID'), '#markup' => $form_id,'#weight' => -100,); }
  • 8. Configure option The configure directive, optional but highly recommended, lets you provide the path to your modules configuration page. Drupal uses this path to provide a link on the Modules administration page when the module is enabled. you have to mention in .info file. The following is an example of a configure directive from the core search module: configure = admin/config/search/settings
  • 9. Module enable/disable/uninstall place your module on the root_directory/sites/all/module/module. Goto Admin Menu => modules. you can see all core and contributed modules.click on enabled option and save. if want disable uncheck the option and save for the same. Also any configuration and permission needed for the module you can see configure & permission link corresponding to the module name. To uninstall - Admin Menu => modules you will find uninstall tab on top right. check the list of module proceed uninstall. uninstall option will completely remove your physical datatables related to the modules.
  • 11. Hooks The hooks allows in module do something before the it is get executed. Its almost like event listener whenever an action taken place in drupal like saving,editing,deleting comments, node, users the system invites all any module involved.Every hook is an opportunity for your module to take action in response to something Drupal is doing. Apptx around 250 hooks are there in drupal system. hook is the placeholder your module name will be replaced there.
  • 12. Sample Code function mymodule_help($path, $arg) { if ($path == 'admin/structure') { return t('This site has stuff!'); } } Styling Your Module : Adding a CSS File you can all the css files needed for your module in .info file. stylesheets[all][] = mymodule.css