Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Drupal module development


Published on

Published in: Technology
  • Be the first to comment

Drupal module development

  1. 1. Drupal Module Development“Hands-on”Amit Vyas Gupta
  2. 2. Overview• Drupal Architecture• Types of Drupal Modules• Module Architecture• Hooks • Hands On Module
  3. 3. Drupal ArchitectureTechnology Stack L(/W)AMPCode Base (Drupal 7)Database
  4. 4. OperatingSystemWeb ServerLanguageDatabase Abstraction LayerTechnology StackDatabase4
  5. 5. Types of Drupal ModulesCore ModulesContributed ModulesCustom Modules
  6. 6. Core Modules• Block:Restricted to web administrator access only.• Filter:Authorized users and web administrators can choose from eitherFiltered or Full HTML Input formats.• Node:Responsible for content.• System:Responsible for cron and caching.Primary Web Site Admin. only.• User:User Management, Roles, Permissions.Web administrator access only.6
  7. 7. Contributed ModulesThere are very high chances that what you arelooking for has already been developed  Google -> <searchkeywords> -cvs
  8. 8. No Luck!! 
  9. 9. Time to get hands dirty !!How?
  10. 10. Custom Modules• To extend functionality of contributed modules.• To build features that are specific to your site.• To build features that are not available through core orcontributed modules.10
  11. 11. Make sure to look insiderelated modulesRelated =>Modules that do things which are onlyslightly different or slightly similar to thethings that you wound want yourmodule to do.
  12. 12. Module Architecture“The building blocks of a module”The .info file The .install fileThe .modulefileThe .inc file
  13. 13. .info file• Drupal uses .info files (aka, "dot info files") to store metadataabout themes and modules. Various Drupal components use theinformation in this file for module management.• The .info file should have the same name as the .module fileand reside in the same directory. For example, if our module isnamed drupal_training.module then your .info file should benamed
  14. 14. Filename = “Drupal Training”description = “Module for Drupal Training Day”core = 7.xpackage = “Training”name (Required) The displayed name of your module. It should followthe Drupal capitalization standard: only the first letter of the first word iscapitalized ("Example module"). Spaces are allowed as the name is usedmainly for the display purposes.description (Required) A short, preferably one line description that will tell theadministrator what this module does on the module administration page.core (Required) The version of Drupal that your module is for. For Drupal 6 this wouldbe 6.x, Drupal 7 would be 7.x, etc.14
  15. 15. .inc file• When Drupal loads a page, it loads all the .modules files of allthe active/enabled modules.• If you have .inc (aka dot inc) file then .module will be loadedwhen page loads BUT the inc file will not be loaded• .inc file will be loaded for the specific page/path• .inc file helps to reduce code loaded on a specific page/path• hook_menu allows you to specify a .inc file for a specific path15
  16. 16. Introduction to HooksWhat are hooks?Why should I care?16
  17. 17. What are hooks?• A hook is really nothing more than a function that matches thepattern of a call to the module functions .• You can say that hook is a simple callback function that is calledon specific events.• Pattern modulename_hookname()• For example, if you want to do some operation on userlogin, say sending an email to administrator on user logins intothe site, then no need to change the code in user module.• Implement hook_user on your own module say “alert” bydefining function in your module file called alert_user and writecode to send an email to administrator here.17
  18. 18. Why should I care?• Modules Extends it’s functionality through hook system.• One module communicates through other module throughhooks.• The Hooks API provides a common naming standard forhooks, allowing developers to implement them in custommodules without needing to engage in extensive programming.• The Hooks API allows developers to create their own hooks thatother modules can access, that leverage the same techniquesused in core Drupal.• Many hooks are state aware, and operate differently dependingon what Drupal is actually doing when the hook is triggered.18
  19. 19. Permissions, Access Controlhook_permission
  20. 20. hook_menuDefine menu items and pagecallbacks.
  21. 21. Modify an existing formhook_form_alter
  22. 22. Node operations“The king of all hooks”hook_nodeapi
  23. 23. Major hooks Gotcha: Not implementing the case delete.Especially dangerous when modules owntables have user related data. Just do it in thememory of node/8
  24. 24. Tools we can use… DATABASE API ~ 2200 more
  25. 25. 25Amit Vyas Gupta