0
Module Development



      Ipsita Mishra
    Siva Kumar Epari


    http://melity.com
About Us

●Ipsita Mishra
✔4 years of Drupal experience

✔Tech lead

✔Webadmin & Core member of Drupal Hyderabad



●Siva K...
Types of Modules



  Core Modules

 Contrib Modules

 Custom Module
Core Modules

These are the modules that ships with a Standard
Drupal Release. There are Core Optional and
Core Required m...
Contrib Modules


Over 5800 (as of July 20, 2010) free community-
contributed modules, known as contrib modules,
are avail...
Popular Contrib Modules




These statistics are incomplete; only Drupal websites using
   the Update Status module are in...
Custom Module


A Custom module is one which is local to your
Drupal Project. It's not yet contributed to the
contrib repo...
Custom Module(When to write)

You need to answer few questions before writing a
Custom Module
1. What do you want to achie...
Custom Module(Why to write)


I have 2 reasons to write a Custom module

1. I need a new feature which is not yet availabl...
A simple module directory
        structure



                 modulename.info


    modulename


             modulename...
new.info

                    ; $Id$

                name = Module name
                description = “Module description...
new.module
             <?php

             // $Id$

             function new_form_alter(&$form, &$form_state, $formid){
...
Download examples module from
http://drupal.org/project/examples
http://drupal.org/project/examples
node_example module
hook_node_info()
hook_access()
hook_perm()
hook_perm() Output
http://localhost/drupal-6.19/admin/user/permissions
hook_form()
hook_form() Contd...
hook_validate()
hook_insert()
hook_schema()
hook_install() hook_uninstall()
hook_update()




Preventing SQL injection is easy; db_query provides a way to use
parametrized queries. Drupal's database...
hook_nodeapi()
hook_delete()
hook_load()
hook_view()
hook_theme()
Theme function
Menu System
hook_menu()
Menu Item Types
"type": A bitmask of flags describing properties of the menu
item. Many shortcut bitmasks are provided as ...
hook_menu_alter()
Drupal Blocks
hook_block()
A Block represents some auxiliary content along
with the primary content of the page.
The output is themed
  comment.module
Parameters
hook_block($op = 'list', $delta = 0, $edit = array())
Operation: list
Operation: configure
Operation: save
Operation: view
Developer's Tools


●   Drush
●   Devel and Devel Themer
●   Coder
●   Admin Menu
DRUpal SHell

●   drush dl modulename/themename
●   drush en modulename/themename
●   drush dis modulename/themename
●   d...
Devel

● Devel: Helper functions for Drupal developers.
● Generate content: Accelerate development of

your site or module...
Devel Themer
Coder




This module helps in Code Review
A Sample Analysis by Coder
Resources
http://api.drupal.org




 IRC Channel
 #drupal
 #drupal-support
 #drupal-hyderabad
Thank You
@IpsitaMishra
@siva_epari
Drupal Module Development - OSI Days 2010
Upcoming SlideShare
Loading in...5
×

Drupal Module Development - OSI Days 2010

3,704

Published on

Giving a overview of Drupal API and building a drupal module from scratch. Also

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
3,704
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
90
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Transcript of "Drupal Module Development - OSI Days 2010"

  1. 1. Module Development Ipsita Mishra Siva Kumar Epari http://melity.com
  2. 2. About Us ●Ipsita Mishra ✔4 years of Drupal experience ✔Tech lead ✔Webadmin & Core member of Drupal Hyderabad ●Siva Kumar Epari ✔2 years of Drupal experience ✔Drupal Developer ✔Webadmin & Core member of Drupal Hyderabad
  3. 3. Types of Modules Core Modules Contrib Modules Custom Module
  4. 4. Core Modules These are the modules that ships with a Standard Drupal Release. There are Core Optional and Core Required modules. For example: Node User Block System Filter
  5. 5. Contrib Modules Over 5800 (as of July 20, 2010) free community- contributed modules, known as contrib modules, are available to alter and extend Drupal's core capabilities and add new features or customize Drupal's behavior and appearance.
  6. 6. Popular Contrib Modules These statistics are incomplete; only Drupal websites using the Update Status module are included in the data.
  7. 7. Custom Module A Custom module is one which is local to your Drupal Project. It's not yet contributed to the contrib repository.
  8. 8. Custom Module(When to write) You need to answer few questions before writing a Custom Module 1. What do you want to achieve by this custom module? 2. Did you search the Contrib Repository to see if a module is already available for that feature? 3. Have you enabled all possible Configurations of the Core & Contrib module to check if they offer you the feature you require? If your answer is, “Yes, I have done enough research and am sure I have to write the code now”, then go ahead ....
  9. 9. Custom Module(Why to write) I have 2 reasons to write a Custom module 1. I need a new feature which is not yet available in Drupal, and probably can be contributed as a Contrib Module. 2. I don't want to keep adding additional modules to my site for small tweaks, which I can manage in only one custom module for my website. Don't be too much dependent on Contribs.
  10. 10. A simple module directory structure modulename.info modulename modulename.module
  11. 11. new.info ; $Id$ name = Module name description = “Module description” modulename.info core = Drupal version (e.g.: 5.x, 6.x) package = Package name ; $Id$ name = Text Captcha description = “Text Captcha” new.info core = 6.x package = Osidays
  12. 12. new.module <?php // $Id$ function new_form_alter(&$form, &$form_state, $formid){ if(substr($formid, -9) == 'node_form'){ $form['captcha'] = array( '#type' => 'textfield', '#title' => 'Captcha Question : What is 5 + 3?', ); $form['#validate'][] = '_new_validate'; $form['#submit'][] = '_new_submit'; new.module } } function _new_validate($form, &$form_state){ if($form_state['values']['captcha'] != '8'){ form_set_error('captcha', 'Your Captcha answer is wrong! So you are not a human or you don't know counting :D'); } } function _new_submit($form, &$form_state){ drupal_set_message('You are a human!'); }
  13. 13. Download examples module from http://drupal.org/project/examples
  14. 14. http://drupal.org/project/examples
  15. 15. node_example module
  16. 16. hook_node_info()
  17. 17. hook_access()
  18. 18. hook_perm()
  19. 19. hook_perm() Output http://localhost/drupal-6.19/admin/user/permissions
  20. 20. hook_form()
  21. 21. hook_form() Contd...
  22. 22. hook_validate()
  23. 23. hook_insert()
  24. 24. hook_schema()
  25. 25. hook_install() hook_uninstall()
  26. 26. hook_update() Preventing SQL injection is easy; db_query provides a way to use parametrized queries. Drupal's database functions replace the sprintf-like placeholders with the properly escaped arguments in order of appearance: %d - integers %f - floats %s - strings, enclose in single quotes %b - binary data, do not enclose in single quotes
  27. 27. hook_nodeapi()
  28. 28. hook_delete()
  29. 29. hook_load()
  30. 30. hook_view()
  31. 31. hook_theme()
  32. 32. Theme function
  33. 33. Menu System
  34. 34. hook_menu()
  35. 35. Menu Item Types "type": A bitmask of flags describing properties of the menu item. Many shortcut bitmasks are provided as constants in menu.inc: * MENU_NORMAL_ITEM: Normal menu items show up in the menu tree and can be moved/hidden by the administrator. * MENU_CALLBACK: Callbacks simply register a path so that the correct function is fired when the URL is accessed. * MENU_SUGGESTED_ITEM: Modules may "suggest" menu items that the administrator may enable. * MENU_LOCAL_TASK: Local tasks are rendered as tabs by default. * MENU_DEFAULT_LOCAL_TASK: Every set of local tasks should provide one "default" task, that links to the same path as its parent when clicked. If the "type" key is omitted, MENU_NORMAL_ITEM is assumed.
  36. 36. hook_menu_alter()
  37. 37. Drupal Blocks
  38. 38. hook_block() A Block represents some auxiliary content along with the primary content of the page.
  39. 39. The output is themed comment.module
  40. 40. Parameters hook_block($op = 'list', $delta = 0, $edit = array())
  41. 41. Operation: list
  42. 42. Operation: configure
  43. 43. Operation: save
  44. 44. Operation: view
  45. 45. Developer's Tools ● Drush ● Devel and Devel Themer ● Coder ● Admin Menu
  46. 46. DRUpal SHell ● drush dl modulename/themename ● drush en modulename/themename ● drush dis modulename/themename ● drush pm-uninstall modulename/themename ● drush cc Resource: http://drupal.org/files/drush-cheat-sheet.pdf
  47. 47. Devel ● Devel: Helper functions for Drupal developers. ● Generate content: Accelerate development of your site or module by quickly generating nodes, comments, terms, users, and more. ● Node Access Summary: View the node access entries for the node(s) that are shown on a page.
  48. 48. Devel Themer
  49. 49. Coder This module helps in Code Review
  50. 50. A Sample Analysis by Coder
  51. 51. Resources http://api.drupal.org IRC Channel #drupal #drupal-support #drupal-hyderabad
  52. 52. Thank You @IpsitaMishra @siva_epari
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×