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

More Related Content

What's hot

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 NepalChandra Prakash Thapa
 
Debugging WordPress
Debugging WordPressDebugging WordPress
Debugging WordPressMario Peshev
 
Drupal 8 theming deep dive
Drupal 8 theming deep diveDrupal 8 theming deep dive
Drupal 8 theming deep diveRomain Jarraud
 
Towards an Alternate WordPress Theme Structure
Towards an Alternate WordPress Theme StructureTowards an Alternate WordPress Theme Structure
Towards an Alternate WordPress Theme StructureGraham Armfield
 
Wordpress template hierarchy
Wordpress template hierarchyWordpress template hierarchy
Wordpress template hierarchyStockton Group
 
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 Studioelliando dias
 
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 DrupalMumbai
 
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 CorneliusWPJoburg
 
WordPress Theme Structure
WordPress Theme StructureWordPress Theme Structure
WordPress Theme Structurekeithdevon
 
One Man Band - Drupal Lightning Talks
One Man Band - Drupal Lightning TalksOne Man Band - Drupal Lightning Talks
One Man Band - Drupal Lightning TalksMark Jarrell
 
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 SOLRExove
 
Drupal Now! - Introduction to Drupal
Drupal Now! - Introduction to DrupalDrupal Now! - Introduction to Drupal
Drupal Now! - Introduction to DrupalAlozie Nwosu
 
WordPress Themes and Plugins
WordPress Themes and PluginsWordPress Themes and Plugins
WordPress Themes and Pluginssuperann
 
Building a Mobile Drupal Site
Building a Mobile Drupal SiteBuilding a Mobile Drupal Site
Building a Mobile Drupal SiteMark Jarrell
 
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 Structuregregdavispsu
 

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

Drupal Views development
Drupal Views developmentDrupal Views development
Drupal Views developmentOSInet
 
Drupal from development point of view
Drupal from development point of viewDrupal from development point of view
Drupal from development point of viewNikolay Ignatov
 
Psychometrics for Clinical Skills Assessment
Psychometrics for Clinical Skills AssessmentPsychometrics for Clinical Skills Assessment
Psychometrics for Clinical Skills AssessmentINSPIRE_Network
 
Drupal 7 module development
Drupal 7 module developmentDrupal 7 module development
Drupal 7 module developmentAdam Kalsey
 
Creating Custom Drupal Modules
Creating Custom Drupal ModulesCreating Custom Drupal Modules
Creating Custom Drupal Modulestanoshimi
 
Introduction to Drupal (7) Theming
Introduction to Drupal (7) ThemingIntroduction to Drupal (7) Theming
Introduction to Drupal (7) ThemingRobert Carr
 

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

The Drupal 7 Worst Practices Catalogue
The Drupal 7 Worst Practices CatalogueThe Drupal 7 Worst Practices Catalogue
The Drupal 7 Worst Practices CatalogueAlexandre Israël
 
Open Source Content Management Systems
Open Source Content Management SystemsOpen Source Content Management Systems
Open Source Content Management SystemsMatthew Turland
 
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 practicesSynapseindiappsdevelopment
 
Drupal module development training delhi
Drupal module development training delhiDrupal module development training delhi
Drupal module development training delhiunitedwebsoft
 
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 ConceptsMicky Metts
 
Synapseindia drupal intro 0
Synapseindia drupal intro 0Synapseindia drupal intro 0
Synapseindia drupal intro 0saritasingh19866
 
Architecture of Drupal - Drupal Camp
Architecture of Drupal - Drupal CampArchitecture of Drupal - Drupal Camp
Architecture of Drupal - Drupal CampDipen Chaudhary
 
Intro to drupal module internals asheville
Intro to drupal module internals ashevilleIntro to drupal module internals asheville
Intro to drupal module internals ashevillecgmonroe
 
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 overviewDrupalMumbai
 
Introduction To Drupal
Introduction To DrupalIntroduction To Drupal
Introduction To DrupalLauren 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 2009Emma Jane Hogbin Westby
 
Drupal 8 - Corso frontend development
Drupal 8 - Corso frontend developmentDrupal 8 - Corso frontend development
Drupal 8 - Corso frontend developmentsparkfabrik
 
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 ThemeAdolfo Nasol
 
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 2010Mediacurrent
 
Drupal Theme Development - DrupalCon Chicago 2011
Drupal Theme Development - DrupalCon Chicago 2011Drupal Theme Development - DrupalCon Chicago 2011
Drupal Theme Development - DrupalCon Chicago 2011Ryan Price
 
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 2Acquia
 

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.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.