SlideShare a Scribd company logo
1 of 22
Intro To DRUPAL Module Internals Greg Monroe Triangle Drupal Users Group Aug 11, 2011
Skills and Tools A very basic knowledge of PhP (e.g. can kinda follow the basic logic but may not be able to write it) A decent (plain) text editor ( e.g. Notepad++, Text Edit, Gedit ) Optionally, you could find a more PhP friendly editor that displays a function list and allows for searching thru multiple file/directories. (SciTE, Geany, NotePad++ with plugins, Eclipse, Aptana, Zend…)
What we won’t cover Finding modules Downloading modules Installing modules Enabling modules Configuring module
What will be covered How Modules work overview Basic module file structure Finding modules The .info file The .module file Finding help in the module Finding module menu items (pages) Finding blocks a module supplies What does the module allows to be themed Finding permissions Finding views the module creates
How modules work Core finds them via admin/build/module Stores info about them in System DB table Enabling module sets flag in System DB table, creates required DB tables, does initial setup and registration duties. Main code for modules loaded at page “boot”. Module code gets called via “hooks” by core and other modules Module Magic happens
Some Hook Fundamentals There are many hooks from many sources but a good starting place is:http://api.drupal.org/api/drupal/includes--module.inc/group/hooks/6 Hooks are generally documented as hook_name, e.g. hook_menu or hook_block Hooks implementations are basically functions that follow a specific naming format.  So, for the “foo” module to implement hook_menu, it must have a function named, foo_menu.
Useful Module Splunking Hooks Hook_help Hook_menu Hook_block Hook_theme Hook_perm Hook_views_api Note:  	You can find full documentation on hook by googling: 	“Drupalapi hook_<name>”
Module File Structure All module files live under a common directory, who’s name is the module “basename”.  E.g., Organic group is “og”, Node Gallery uses node_gallery, CCK uses content.Note:  Module base directories can exist under other modules, e.g. og_views is found in og/modules/og_views… At a minimum, a module base directory needs two files:		<basename>.info  (e.g. og.info)		<basename>.module (e.g. og.module)
An Example of Module files The Organic Group Module
Finding a Module Finding a module that is creating some page or block from the displayed page is hard… and beyond this talk… If you know the “Human name”, e.g. Organic Groups, you can find the base name using FireBug and the Modules page.  Just inspect the enable checkbox and look at the value. Knowing this, see if you can download it from Drupal.org.  Looking at a module outside your web server is MUCH safer. But if you think your site’s code is different or you can’t find the Drupal Project….
Where’s Wald..err..the Module Modules can live many places… but by convention they generally live under one of three directories:	<drupal root>/modules (Core only!)	<drupal root>/sites/all/modules (for all sites)	<drupal root>/sites/default/modulesNote: In multisite setups, the default part above may be your host name, e.g. www.my.comNext check to see if a basename directory exists… if not, use a file search tool to look for <basename>.info under these directories.
Module Files Required: 	<basename>.info<basename>.module Recommended: 	README(.txt)LICENSE(.txt)<basename>.install Naming Conventions: *.inc – Include files loaded	 as needed *.pages.inc – code needed	 for general pages *.admin.inc – code needed	 for admin pages *.tpl.php – Override-able       theme template files
The .info file The module.info file contains the basic description of the module.
The .Module File The <Basename>.module file contains the core code for the module and generally all the hooks we’re interested in.
Finding Hooks With the .module file in an editor: If your editor show functions, just look for the _<hook name> postfix Search for “hook_<hook name>”  Search for <basename>_<hook name> Look for _<hook name>
Hook_Help Notes: Supplies text for Drupal Advanced help system Case statements   – URL help applies to Return statements   - Help text
Hook_Menu Notes: Defines URLs (as menu items or just pages) for “pages” the module  creates $items[…] statements   – URL of page  - %xxx indicate argument     substitution ‘title’ array key    - Menu/Page title ‘page callback’ array key   - function to create page ‘access callback’ array key   - function that determines     access
Hook_Block Notes: If ($op == list) section - Defines blocks this     module adds ‘info’ array key – Name shown in block    admin display The “view” op (not shown) defines how the block  contents are created The “configure” op (not  shown)  defines any block specific configuration  options
Hook_Theme Notes: ‘<basename>_xxx’ keys  - These define the theme   “hooks” for this module ‘arguments’ key  - Defines the values passed    to the theme hook ‘template’ key  - Indicates this theme hook     is a .tpl.php template file ‘path’ key  - The directory the tpl.php     file is located. Code for non-template hooks will be in theme_<name> functions.
Hook_Perm Notes: Defines the permissions this module uses. Note that many modules use PhP constants to define  permissions.  So, look at  these to get the names used in the permission settings  screens.
Hook_views_api If you find this hook, you know that this module supports views and might be supplying blocks and pages thru views it installs. The path option will indicate where the views related .inc files will “live”.  If you look thru these you will generally find the names of views this module creates
Questions / More Info Pro Drupal Development is the “bible” Drupal API site has lots of docs on hook DrupalContrib.org has lots of docs on non-core hooks Of course Drupal.org and general search will help you find lots of good stuff.

More Related Content

Viewers also liked

Saja Pharmaceuticals Corporate Profile - Saudi Japanese - JAPAN - KSA-
Saja Pharmaceuticals Corporate Profile - Saudi Japanese - JAPAN - KSA- Saja Pharmaceuticals Corporate Profile - Saudi Japanese - JAPAN - KSA-
Saja Pharmaceuticals Corporate Profile - Saudi Japanese - JAPAN - KSA-
SAJA Pharmaceuticals
 
Solucion lectura 3[1]
Solucion lectura 3[1]Solucion lectura 3[1]
Solucion lectura 3[1]
guest531f33
 
Osb studija slucaja sgsb-a.ppt [compatibility m
Osb studija slucaja sgsb-a.ppt [compatibility mOsb studija slucaja sgsb-a.ppt [compatibility m
Osb studija slucaja sgsb-a.ppt [compatibility m
Oracle Hrvatska
 
Polypill poster Istanbul, Nov 2014
Polypill poster Istanbul, Nov 2014Polypill poster Istanbul, Nov 2014
Polypill poster Istanbul, Nov 2014
Dr. Anand Sudhalkar
 
Charla con funcionarios versión corta
Charla con funcionarios versión cortaCharla con funcionarios versión corta
Charla con funcionarios versión corta
luzserrano
 

Viewers also liked (19)

Study Abroad In A Transparent World
Study Abroad In A Transparent WorldStudy Abroad In A Transparent World
Study Abroad In A Transparent World
 
Intro to drupal module internals asheville
Intro to drupal module internals ashevilleIntro to drupal module internals asheville
Intro to drupal module internals asheville
 
microwaves
microwavesmicrowaves
microwaves
 
C:\Documents And Settings\Acloutier\Desktop\Mat March11,2009 Frames Of Mind Umd
C:\Documents And Settings\Acloutier\Desktop\Mat March11,2009 Frames Of Mind UmdC:\Documents And Settings\Acloutier\Desktop\Mat March11,2009 Frames Of Mind Umd
C:\Documents And Settings\Acloutier\Desktop\Mat March11,2009 Frames Of Mind Umd
 
Maternal and Child Anemia- Why, what works, what needs more work?
Maternal and Child Anemia- Why, what works, what needs more work?Maternal and Child Anemia- Why, what works, what needs more work?
Maternal and Child Anemia- Why, what works, what needs more work?
 
Mirtha cunza
Mirtha cunzaMirtha cunza
Mirtha cunza
 
Short CV of Kala(1) (1)
Short CV of Kala(1) (1)Short CV of Kala(1) (1)
Short CV of Kala(1) (1)
 
PresentacióN1
PresentacióN1PresentacióN1
PresentacióN1
 
Tvb Media Comparisons 2010 Persons
Tvb Media Comparisons 2010 PersonsTvb Media Comparisons 2010 Persons
Tvb Media Comparisons 2010 Persons
 
Saja Pharmaceuticals Corporate Profile - Saudi Japanese - JAPAN - KSA-
Saja Pharmaceuticals Corporate Profile - Saudi Japanese - JAPAN - KSA- Saja Pharmaceuticals Corporate Profile - Saudi Japanese - JAPAN - KSA-
Saja Pharmaceuticals Corporate Profile - Saudi Japanese - JAPAN - KSA-
 
Solucion lectura 3[1]
Solucion lectura 3[1]Solucion lectura 3[1]
Solucion lectura 3[1]
 
Social Media - tips en de basis
Social Media - tips en de basisSocial Media - tips en de basis
Social Media - tips en de basis
 
Topshops Malik
Topshops MalikTopshops Malik
Topshops Malik
 
Osb studija slucaja sgsb-a.ppt [compatibility m
Osb studija slucaja sgsb-a.ppt [compatibility mOsb studija slucaja sgsb-a.ppt [compatibility m
Osb studija slucaja sgsb-a.ppt [compatibility m
 
Polypill poster Istanbul, Nov 2014
Polypill poster Istanbul, Nov 2014Polypill poster Istanbul, Nov 2014
Polypill poster Istanbul, Nov 2014
 
Partyasart2010
Partyasart2010Partyasart2010
Partyasart2010
 
Charla con funcionarios versión corta
Charla con funcionarios versión cortaCharla con funcionarios versión corta
Charla con funcionarios versión corta
 
xarxes
xarxesxarxes
xarxes
 
Il calzaturiero di san mauro pascoli 2011
Il calzaturiero di san mauro pascoli   2011Il calzaturiero di san mauro pascoli   2011
Il calzaturiero di san mauro pascoli 2011
 

More from cgmonroe

More from cgmonroe (13)

Structured SEO Data Overview and How To
Structured SEO Data Overview and How ToStructured SEO Data Overview and How To
Structured SEO Data Overview and How To
 
Structured SEO Data: An overview and how to for Drupal
Structured SEO Data:  An overview and how to for DrupalStructured SEO Data:  An overview and how to for Drupal
Structured SEO Data: An overview and how to for Drupal
 
Tips on Securing Drupal Sites - DrupalCamp Atlanta (DCA)
Tips on Securing Drupal Sites - DrupalCamp Atlanta (DCA)Tips on Securing Drupal Sites - DrupalCamp Atlanta (DCA)
Tips on Securing Drupal Sites - DrupalCamp Atlanta (DCA)
 
Tips on Securing Drupal Sites
Tips on Securing Drupal SitesTips on Securing Drupal Sites
Tips on Securing Drupal Sites
 
Becoming "Facet"-nated with Search API
Becoming "Facet"-nated with Search APIBecoming "Facet"-nated with Search API
Becoming "Facet"-nated with Search API
 
Using Content Delivery Networks with Drupal
Using Content Delivery Networks with DrupalUsing Content Delivery Networks with Drupal
Using Content Delivery Networks with Drupal
 
Solr facets and custom indices
Solr facets and custom indicesSolr facets and custom indices
Solr facets and custom indices
 
HTML Purifier, WYSIWYG, and TinyMCE
HTML Purifier, WYSIWYG, and TinyMCEHTML Purifier, WYSIWYG, and TinyMCE
HTML Purifier, WYSIWYG, and TinyMCE
 
Using the Features API
Using the Features APIUsing the Features API
Using the Features API
 
The Drupal Strongarm Module - Tips and Tricks.
The Drupal Strongarm Module - Tips and Tricks.The Drupal Strongarm Module - Tips and Tricks.
The Drupal Strongarm Module - Tips and Tricks.
 
Intro to CSS Selectors in Drupal
Intro to CSS Selectors in DrupalIntro to CSS Selectors in Drupal
Intro to CSS Selectors in Drupal
 
Drupal Workflow Concepts
Drupal Workflow ConceptsDrupal Workflow Concepts
Drupal Workflow Concepts
 
TriDUG WebFM Presentation
TriDUG WebFM PresentationTriDUG WebFM Presentation
TriDUG WebFM Presentation
 

Recently uploaded

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Recently uploaded (20)

A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 

Intro to Drupal Module Internals

  • 1. Intro To DRUPAL Module Internals Greg Monroe Triangle Drupal Users Group Aug 11, 2011
  • 2. Skills and Tools A very basic knowledge of PhP (e.g. can kinda follow the basic logic but may not be able to write it) A decent (plain) text editor ( e.g. Notepad++, Text Edit, Gedit ) Optionally, you could find a more PhP friendly editor that displays a function list and allows for searching thru multiple file/directories. (SciTE, Geany, NotePad++ with plugins, Eclipse, Aptana, Zend…)
  • 3. What we won’t cover Finding modules Downloading modules Installing modules Enabling modules Configuring module
  • 4. What will be covered How Modules work overview Basic module file structure Finding modules The .info file The .module file Finding help in the module Finding module menu items (pages) Finding blocks a module supplies What does the module allows to be themed Finding permissions Finding views the module creates
  • 5. How modules work Core finds them via admin/build/module Stores info about them in System DB table Enabling module sets flag in System DB table, creates required DB tables, does initial setup and registration duties. Main code for modules loaded at page “boot”. Module code gets called via “hooks” by core and other modules Module Magic happens
  • 6. Some Hook Fundamentals There are many hooks from many sources but a good starting place is:http://api.drupal.org/api/drupal/includes--module.inc/group/hooks/6 Hooks are generally documented as hook_name, e.g. hook_menu or hook_block Hooks implementations are basically functions that follow a specific naming format. So, for the “foo” module to implement hook_menu, it must have a function named, foo_menu.
  • 7. Useful Module Splunking Hooks Hook_help Hook_menu Hook_block Hook_theme Hook_perm Hook_views_api Note: You can find full documentation on hook by googling: “Drupalapi hook_<name>”
  • 8. Module File Structure All module files live under a common directory, who’s name is the module “basename”. E.g., Organic group is “og”, Node Gallery uses node_gallery, CCK uses content.Note: Module base directories can exist under other modules, e.g. og_views is found in og/modules/og_views… At a minimum, a module base directory needs two files: <basename>.info (e.g. og.info) <basename>.module (e.g. og.module)
  • 9. An Example of Module files The Organic Group Module
  • 10. Finding a Module Finding a module that is creating some page or block from the displayed page is hard… and beyond this talk… If you know the “Human name”, e.g. Organic Groups, you can find the base name using FireBug and the Modules page. Just inspect the enable checkbox and look at the value. Knowing this, see if you can download it from Drupal.org. Looking at a module outside your web server is MUCH safer. But if you think your site’s code is different or you can’t find the Drupal Project….
  • 11. Where’s Wald..err..the Module Modules can live many places… but by convention they generally live under one of three directories: <drupal root>/modules (Core only!) <drupal root>/sites/all/modules (for all sites) <drupal root>/sites/default/modulesNote: In multisite setups, the default part above may be your host name, e.g. www.my.comNext check to see if a basename directory exists… if not, use a file search tool to look for <basename>.info under these directories.
  • 12. Module Files Required: <basename>.info<basename>.module Recommended: README(.txt)LICENSE(.txt)<basename>.install Naming Conventions: *.inc – Include files loaded as needed *.pages.inc – code needed for general pages *.admin.inc – code needed for admin pages *.tpl.php – Override-able theme template files
  • 13. The .info file The module.info file contains the basic description of the module.
  • 14. The .Module File The <Basename>.module file contains the core code for the module and generally all the hooks we’re interested in.
  • 15. Finding Hooks With the .module file in an editor: If your editor show functions, just look for the _<hook name> postfix Search for “hook_<hook name>” Search for <basename>_<hook name> Look for _<hook name>
  • 16. Hook_Help Notes: Supplies text for Drupal Advanced help system Case statements – URL help applies to Return statements - Help text
  • 17. Hook_Menu Notes: Defines URLs (as menu items or just pages) for “pages” the module creates $items[…] statements – URL of page - %xxx indicate argument substitution ‘title’ array key - Menu/Page title ‘page callback’ array key - function to create page ‘access callback’ array key - function that determines access
  • 18. Hook_Block Notes: If ($op == list) section - Defines blocks this module adds ‘info’ array key – Name shown in block admin display The “view” op (not shown) defines how the block contents are created The “configure” op (not shown) defines any block specific configuration options
  • 19. Hook_Theme Notes: ‘<basename>_xxx’ keys - These define the theme “hooks” for this module ‘arguments’ key - Defines the values passed to the theme hook ‘template’ key - Indicates this theme hook is a .tpl.php template file ‘path’ key - The directory the tpl.php file is located. Code for non-template hooks will be in theme_<name> functions.
  • 20. Hook_Perm Notes: Defines the permissions this module uses. Note that many modules use PhP constants to define permissions. So, look at these to get the names used in the permission settings screens.
  • 21. Hook_views_api If you find this hook, you know that this module supports views and might be supplying blocks and pages thru views it installs. The path option will indicate where the views related .inc files will “live”. If you look thru these you will generally find the names of views this module creates
  • 22. Questions / More Info Pro Drupal Development is the “bible” Drupal API site has lots of docs on hook DrupalContrib.org has lots of docs on non-core hooks Of course Drupal.org and general search will help you find lots of good stuff.