SlideShare a Scribd company logo
1 of 18
Creating Drupal Modules A somewhat less then definitive guide to
Who is this bozo? Adam A. Gregory Drupal Developer for 4 years PHP developer for 8+ years Contribute and maintains modules on Drupal.org Currently work as a freelance Drupal ninja. Worked on Drupal sites large and small. http://AdamAGregory.com
Why create a module? New functionality Override existing functionality Forms Nodes Users Search Theming Combination of the two Almost every site needs a custom module
Before you start Is there an existing module Drupal.org (http://drupal.org/project/Modules/name) IRC Mailing list (development@drupal.org) What you need PHP/SQL/HTML/CSS skill IDE Test site Drupal API (http://api.lullabot.com)
Setting up File Structure Module Folder (custom_pub) .info file (custom_pub.info) .module file (custom_pub.module) .install file (custom_pub.install) Other files/folders Theme folder .tpl.php files Css/js folders .inc files
.info File Where Drupal gathers all the knowledge about your module Contains module name, decsription, group, version, requirements and dependencies
;$Id: $ name=Custom Publishing Options description=Adds the ability to add Custom publishing options to the node Add/Edit form. core=6.x package=Other
.module File Must have the same name is .info file Contains the PHP code for your module All core hooks must be included in this file to work Should be kept small as it is loaded on every page load Dynamically loading inc files either via hook_menu or by loading them when a hook is called
.install File Only needed if you module makes ANY sort of DB changes Invokes hook_install, hook_uninstall, hook_update_##, and hook_schema
<?php //;$Id: custom_pub.install,v 1.1 2010/01/20 21:13:05 arcaneadam Exp $ /**  * Implementation of hook_uninstall()  */ function custom_pub_uninstall() { $types = variable_get('custom_pub_types', array()); $ret=array(); foreach ($types as $type => $name) { db_drop_field($ret,'node',$type); } variable_del('custom_pub_types'); }
Theres a hook for that Drupal works off a hooking system similar to an Observer pattern. Main hooks most modules use Hook_menu Hook_help Hook_form_alter Hook_user Hook_nodeapi API site can help you find other hooks
Organizing Your Code .info and .module are the only required files for a module Keep html/css/js in separate files and not hard coded into .module files Functions for specific pages should moved into .inc files & loaded dynamically Any calls to module files(.inc, .css, .js) should use drupal_get_path($type, $name) for css/js or module_load_include for php
Organizing your code cont. Remember you shouldn’t hard code things like internal links, file paths, etc as you don’t know what sites will use your module and how. Keep your code dynamic and reusable Keep file sizes small and load them when needed for better performance
Finishing Up Load you module into a test site and enable it. Test! Test! Test! Stuff won’t work, you’ll have errors, and things will go crazy DON’T PANIC! It happens, take your time and debug the issues. Use Google, the API, IRC, Forums, Lists, Groups, etc. that are available for help.
A few words about security? Never, ever under any circumstances trust User Input. Drupal provides many functions and resources to properly secure your code. Visit http://drupal.org/writing-secure-code for more info.
Contributing Back http://drupal.org/contribute If you have created something that will be widely useful, or al least you think it will be, you may want to get it listed on Drupal.org, but how? The process can be painful, long, and hit and miss. Remember the D.o maintainers are volunteers. Requires knowledge of CVS(Blah!)
Resources API: http://api.lullabot.comhttp://api.drupal.org Security and coding standards: http://drupal.org/node/360052 Module Developers Guide: http://drupal.org/developing/modules Developing for Drupal: http://drupal.org/contributors-guide IRC: #drupal, #drupal-nc Mailing list: development@drupal.org

More Related Content

What's hot

Developing a Struts & Tiles application using WebSphere Studio
Developing a Struts & Tiles application using WebSphere StudioDeveloping a Struts & Tiles application using WebSphere Studio
Developing a Struts & Tiles application using WebSphere Studio
elliando dias
 
Making your Drupal fly with Apache SOLR
Making your Drupal fly with Apache SOLRMaking your Drupal fly with Apache SOLR
Making your Drupal fly with Apache SOLR
Exove
 

What's hot (20)

WordPress theme development from scratch : ICT MeetUp 2013 Nepal
WordPress theme development from scratch : ICT MeetUp 2013 NepalWordPress theme development from scratch : ICT MeetUp 2013 Nepal
WordPress theme development from scratch : ICT MeetUp 2013 Nepal
 
Debugging WordPress
Debugging WordPressDebugging WordPress
Debugging WordPress
 
Wordpress theme framework : Roots
Wordpress theme framework : RootsWordpress theme framework : Roots
Wordpress theme framework : Roots
 
Drupal 8 theming deep dive
Drupal 8 theming deep diveDrupal 8 theming deep dive
Drupal 8 theming deep dive
 
Towards an Alternate WordPress Theme Structure
Towards an Alternate WordPress Theme StructureTowards an Alternate WordPress Theme Structure
Towards an Alternate WordPress Theme Structure
 
Intrebari Hydro
Intrebari HydroIntrebari Hydro
Intrebari Hydro
 
Wordpress template hierarchy
Wordpress template hierarchyWordpress template hierarchy
Wordpress template hierarchy
 
Joomla 3.x guide
Joomla 3.x guideJoomla 3.x guide
Joomla 3.x guide
 
Developing a Struts & Tiles application using WebSphere Studio
Developing a Struts & Tiles application using WebSphere StudioDeveloping a Struts & Tiles application using WebSphere Studio
Developing a Struts & Tiles application using WebSphere Studio
 
Wordpress as a CMS
Wordpress as a CMSWordpress as a CMS
Wordpress as a CMS
 
Drupal Global Training Day by Drupal Mumbai 6th Sep - Extending Drupal
Drupal Global Training Day by Drupal Mumbai 6th Sep - Extending Drupal Drupal Global Training Day by Drupal Mumbai 6th Sep - Extending Drupal
Drupal Global Training Day by Drupal Mumbai 6th Sep - Extending Drupal
 
&lt;?php + WordPress
&lt;?php + WordPress&lt;?php + WordPress
&lt;?php + WordPress
 
WP Joburg Meetup 10: Genesis Framework by Trish Cornelius
WP Joburg Meetup 10: Genesis Framework by Trish CorneliusWP Joburg Meetup 10: Genesis Framework by Trish Cornelius
WP Joburg Meetup 10: Genesis Framework by Trish Cornelius
 
WordPress Theme Structure
WordPress Theme StructureWordPress Theme Structure
WordPress Theme Structure
 
One Man Band - Drupal Lightning Talks
One Man Band - Drupal Lightning TalksOne Man Band - Drupal Lightning Talks
One Man Band - Drupal Lightning Talks
 
Making your Drupal fly with Apache SOLR
Making your Drupal fly with Apache SOLRMaking your Drupal fly with Apache SOLR
Making your Drupal fly with Apache SOLR
 
Drupal Now! - Introduction to Drupal
Drupal Now! - Introduction to DrupalDrupal Now! - Introduction to Drupal
Drupal Now! - Introduction to Drupal
 
WordPress Themes and Plugins
WordPress Themes and PluginsWordPress Themes and Plugins
WordPress Themes and Plugins
 
Building a Mobile Drupal Site
Building a Mobile Drupal SiteBuilding a Mobile Drupal Site
Building a Mobile Drupal Site
 
Getting Under the Hood - WordPress File & Directory Structure
Getting Under the Hood -  WordPress File & Directory StructureGetting Under the Hood -  WordPress File & Directory Structure
Getting Under the Hood - WordPress File & Directory Structure
 

Viewers also liked (7)

Drupal Views development
Drupal Views developmentDrupal Views development
Drupal Views development
 
Drupal from development point of view
Drupal from development point of viewDrupal from development point of view
Drupal from development point of view
 
Psychometrics for Clinical Skills Assessment
Psychometrics for Clinical Skills AssessmentPsychometrics for Clinical Skills Assessment
Psychometrics for Clinical Skills Assessment
 
Elasticsearch PHP UG BG
Elasticsearch PHP UG BGElasticsearch PHP UG BG
Elasticsearch PHP UG BG
 
Drupal 7 module development
Drupal 7 module developmentDrupal 7 module development
Drupal 7 module development
 
Creating Custom Drupal Modules
Creating Custom Drupal ModulesCreating Custom Drupal Modules
Creating Custom Drupal Modules
 
Introduction to Drupal (7) Theming
Introduction to Drupal (7) ThemingIntroduction to Drupal (7) Theming
Introduction to Drupal (7) Theming
 

Similar to Creating Drupal A Module

Open Source Content Management Systems
Open Source Content Management SystemsOpen Source Content Management Systems
Open Source Content Management Systems
Matthew Turland
 
Drupal module development training delhi
Drupal module development training delhiDrupal module development training delhi
Drupal module development training delhi
unitedwebsoft
 
Introduction To Drupal
Introduction To DrupalIntroduction To Drupal
Introduction To Drupal
Lauren Roth
 
Learning PHP for Drupal Theming, DC Chicago 2009
Learning PHP for Drupal Theming, DC Chicago 2009Learning PHP for Drupal Theming, DC Chicago 2009
Learning PHP for Drupal Theming, DC Chicago 2009
Emma Jane Hogbin Westby
 

Similar to Creating Drupal A Module (20)

Drupal
DrupalDrupal
Drupal
 
The Drupal 7 Worst Practices Catalogue
The Drupal 7 Worst Practices CatalogueThe Drupal 7 Worst Practices Catalogue
The Drupal 7 Worst Practices Catalogue
 
Open Source Content Management Systems
Open Source Content Management SystemsOpen Source Content Management Systems
Open Source Content Management Systems
 
SynapseIndia drupal presentation on drupal best practices
SynapseIndia drupal  presentation on drupal best practicesSynapseIndia drupal  presentation on drupal best practices
SynapseIndia drupal presentation on drupal best practices
 
Drupal module development training delhi
Drupal module development training delhiDrupal module development training delhi
Drupal module development training delhi
 
Drupal 7x Installation - Introduction to Drupal Concepts
Drupal 7x Installation - Introduction to Drupal ConceptsDrupal 7x Installation - Introduction to Drupal Concepts
Drupal 7x Installation - Introduction to Drupal Concepts
 
Synapseindia drupal intro 0
Synapseindia drupal intro 0Synapseindia drupal intro 0
Synapseindia drupal intro 0
 
Architecture of Drupal - Drupal Camp
Architecture of Drupal - Drupal CampArchitecture of Drupal - Drupal Camp
Architecture of Drupal - Drupal Camp
 
Joomla Templates101
Joomla Templates101Joomla Templates101
Joomla Templates101
 
Intro to drupal module internals asheville
Intro to drupal module internals ashevilleIntro to drupal module internals asheville
Intro to drupal module internals asheville
 
13th Sep - Drupal Global Training Day by TCS - Drupal core advanced overview
13th Sep - Drupal Global Training Day by TCS - Drupal core advanced overview13th Sep - Drupal Global Training Day by TCS - Drupal core advanced overview
13th Sep - Drupal Global Training Day by TCS - Drupal core advanced overview
 
Introduction To Drupal
Introduction To DrupalIntroduction To Drupal
Introduction To Drupal
 
Learning PHP for Drupal Theming, DC Chicago 2009
Learning PHP for Drupal Theming, DC Chicago 2009Learning PHP for Drupal Theming, DC Chicago 2009
Learning PHP for Drupal Theming, DC Chicago 2009
 
Drupal 8 - Corso frontend development
Drupal 8 - Corso frontend developmentDrupal 8 - Corso frontend development
Drupal 8 - Corso frontend development
 
Converting (X)HTML/CSS template to Drupal 7 Theme
Converting (X)HTML/CSS template to Drupal 7 ThemeConverting (X)HTML/CSS template to Drupal 7 Theme
Converting (X)HTML/CSS template to Drupal 7 Theme
 
Drupal Theming For Beginners – Danté SELF 2010
Drupal Theming For Beginners – Danté SELF 2010Drupal Theming For Beginners – Danté SELF 2010
Drupal Theming For Beginners – Danté SELF 2010
 
Drupal theme development
Drupal theme developmentDrupal theme development
Drupal theme development
 
Drupal Theme Development - DrupalCon Chicago 2011
Drupal Theme Development - DrupalCon Chicago 2011Drupal Theme Development - DrupalCon Chicago 2011
Drupal Theme Development - DrupalCon Chicago 2011
 
Drupal Webinar
Drupal WebinarDrupal Webinar
Drupal Webinar
 
Ready. Set. Drupal! An Intro to Drupal 8, Part 2
Ready. Set. Drupal! An Intro to Drupal 8, Part 2Ready. Set. Drupal! An Intro to Drupal 8, Part 2
Ready. Set. Drupal! An Intro to Drupal 8, Part 2
 

Creating Drupal A Module

  • 1. Creating Drupal Modules A somewhat less then definitive guide to
  • 2. Who is this bozo? Adam A. Gregory Drupal Developer for 4 years PHP developer for 8+ years Contribute and maintains modules on Drupal.org Currently work as a freelance Drupal ninja. Worked on Drupal sites large and small. http://AdamAGregory.com
  • 3. Why create a module? New functionality Override existing functionality Forms Nodes Users Search Theming Combination of the two Almost every site needs a custom module
  • 4. Before you start Is there an existing module Drupal.org (http://drupal.org/project/Modules/name) IRC Mailing list (development@drupal.org) What you need PHP/SQL/HTML/CSS skill IDE Test site Drupal API (http://api.lullabot.com)
  • 5. Setting up File Structure Module Folder (custom_pub) .info file (custom_pub.info) .module file (custom_pub.module) .install file (custom_pub.install) Other files/folders Theme folder .tpl.php files Css/js folders .inc files
  • 6. .info File Where Drupal gathers all the knowledge about your module Contains module name, decsription, group, version, requirements and dependencies
  • 7. ;$Id: $ name=Custom Publishing Options description=Adds the ability to add Custom publishing options to the node Add/Edit form. core=6.x package=Other
  • 8. .module File Must have the same name is .info file Contains the PHP code for your module All core hooks must be included in this file to work Should be kept small as it is loaded on every page load Dynamically loading inc files either via hook_menu or by loading them when a hook is called
  • 9.
  • 10. .install File Only needed if you module makes ANY sort of DB changes Invokes hook_install, hook_uninstall, hook_update_##, and hook_schema
  • 11. <?php //;$Id: custom_pub.install,v 1.1 2010/01/20 21:13:05 arcaneadam Exp $ /** * Implementation of hook_uninstall() */ function custom_pub_uninstall() { $types = variable_get('custom_pub_types', array()); $ret=array(); foreach ($types as $type => $name) { db_drop_field($ret,'node',$type); } variable_del('custom_pub_types'); }
  • 12. Theres a hook for that Drupal works off a hooking system similar to an Observer pattern. Main hooks most modules use Hook_menu Hook_help Hook_form_alter Hook_user Hook_nodeapi API site can help you find other hooks
  • 13. Organizing Your Code .info and .module are the only required files for a module Keep html/css/js in separate files and not hard coded into .module files Functions for specific pages should moved into .inc files & loaded dynamically Any calls to module files(.inc, .css, .js) should use drupal_get_path($type, $name) for css/js or module_load_include for php
  • 14. Organizing your code cont. Remember you shouldn’t hard code things like internal links, file paths, etc as you don’t know what sites will use your module and how. Keep your code dynamic and reusable Keep file sizes small and load them when needed for better performance
  • 15. Finishing Up Load you module into a test site and enable it. Test! Test! Test! Stuff won’t work, you’ll have errors, and things will go crazy DON’T PANIC! It happens, take your time and debug the issues. Use Google, the API, IRC, Forums, Lists, Groups, etc. that are available for help.
  • 16. A few words about security? Never, ever under any circumstances trust User Input. Drupal provides many functions and resources to properly secure your code. Visit http://drupal.org/writing-secure-code for more info.
  • 17. Contributing Back http://drupal.org/contribute If you have created something that will be widely useful, or al least you think it will be, you may want to get it listed on Drupal.org, but how? The process can be painful, long, and hit and miss. Remember the D.o maintainers are volunteers. Requires knowledge of CVS(Blah!)
  • 18. Resources API: http://api.lullabot.comhttp://api.drupal.org Security and coding standards: http://drupal.org/node/360052 Module Developers Guide: http://drupal.org/developing/modules Developing for Drupal: http://drupal.org/contributors-guide IRC: #drupal, #drupal-nc Mailing list: development@drupal.org