Your SlideShare is downloading. ×
0
Drupal module development
Drupal module development
Drupal module development
Drupal module development
Drupal module development
Drupal module development
Drupal module development
Drupal module development
Drupal module development
Drupal module development
Drupal module development
Drupal module development
Drupal module development
Drupal module development
Drupal module development
Drupal module development
Drupal module development
Drupal module development
Drupal module development
Drupal module development
Drupal module development
Drupal module development
Drupal module development
Drupal module development
Drupal module development
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Drupal module development

380

Published on

Published in: Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
380
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
0
Comments
0
Likes
2
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Drupal Module Development“Hands-on”Amit Vyashttp://drupal.org/user/246119Rachit Guptahttps://drupal.org/user/403301
  • 2. Overview• Drupal Architecture• Types of Drupal Modules• Module Architecture• Hooks • Hands On Module
  • 3. Drupal ArchitectureTechnology Stack L(/W)AMPCode Base (Drupal 7)Database
  • 4. OperatingSystemWeb ServerLanguageDatabase Abstraction LayerTechnology StackDatabase4
  • 5. Types of Drupal ModulesCore ModulesContributed ModulesCustom Modules
  • 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. Contributed ModulesThere are very high chances that what you arelooking for has already been developed  http://drupal.org/project/Modules http://drupalmodules.com/module-finder Google -> site:drupal.org/project <searchkeywords> -cvs
  • 8. No Luck!! 
  • 9. Time to get hands dirty !!How?
  • 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. 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. Module Architecture“The building blocks of a module”The .info file The .install fileThe .modulefileThe .inc file
  • 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 drupal_training.info.13
  • 14. example.info 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. .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. Introduction to HooksWhat are hooks?Why should I care?16
  • 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. 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. Permissions, Access Controlhook_permission
  • 20. hook_menuDefine menu items and pagecallbacks.
  • 21. Modify an existing formhook_form_alter
  • 22. Node operations“The king of all hooks”hook_nodeapi
  • 23. Major hooks http://api.drupal.org/api/function/hook_user Gotcha: Not implementing the case delete.Especially dangerous when modules owntables have user related data. Just do it in thememory of node/8 http://api.drupal.org/api/function/hook_cron http://api.drupal.org/api/function/hook_block
  • 24. Tools we can use… DATABASE API http://api.drupal.org/api/function/drupal_write_records http://api.drupal.org/api/function/user_roles http://api.drupal.org/api/function/format_interval http://api.drupal.org/api/function/user_multiple_role_edit http://api.drupal.org/api/function/user_load http://api.drupal.org/api/function/drupal_mail http://api.drupal.org/api/function/watchdog ~ 2200 more
  • 25. 25Amit Vyashttp://drupal.org/user/246119Rachit Guptahttps://drupal.org/user/403301

×