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

Study Abroad In A Transparent World
Study Abroad In A Transparent WorldStudy Abroad In A Transparent World
Study Abroad In A Transparent WorldPennySchouten
 
Intro to drupal module internals asheville
Intro to drupal module internals ashevilleIntro to drupal module internals asheville
Intro to drupal module internals ashevillecgmonroe
 
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 UmdAnnie c. Cloutier
 
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?jehill3
 
Tvb Media Comparisons 2010 Persons
Tvb Media Comparisons 2010 PersonsTvb Media Comparisons 2010 Persons
Tvb Media Comparisons 2010 PersonsTatia O'Connor
 
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
 
Social Media - tips en de basis
Social Media - tips en de basisSocial Media - tips en de basis
Social Media - tips en de basisWieger Waardenburg
 
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 mOracle Hrvatska
 
Polypill poster Istanbul, Nov 2014
Polypill poster Istanbul, Nov 2014Polypill poster Istanbul, Nov 2014
Polypill poster Istanbul, Nov 2014Dr. Anand Sudhalkar
 
Charla con funcionarios versión corta
Charla con funcionarios versión cortaCharla con funcionarios versión corta
Charla con funcionarios versión cortaluzserrano
 
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 2011Carlos Maculan
 

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

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 Tocgmonroe
 
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 Drupalcgmonroe
 
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)cgmonroe
 
Tips on Securing Drupal Sites
Tips on Securing Drupal SitesTips on Securing Drupal Sites
Tips on Securing Drupal Sitescgmonroe
 
Becoming "Facet"-nated with Search API
Becoming "Facet"-nated with Search APIBecoming "Facet"-nated with Search API
Becoming "Facet"-nated with Search APIcgmonroe
 
Using Content Delivery Networks with Drupal
Using Content Delivery Networks with DrupalUsing Content Delivery Networks with Drupal
Using Content Delivery Networks with Drupalcgmonroe
 
Solr facets and custom indices
Solr facets and custom indicesSolr facets and custom indices
Solr facets and custom indicescgmonroe
 
HTML Purifier, WYSIWYG, and TinyMCE
HTML Purifier, WYSIWYG, and TinyMCEHTML Purifier, WYSIWYG, and TinyMCE
HTML Purifier, WYSIWYG, and TinyMCEcgmonroe
 
Using the Features API
Using the Features APIUsing the Features API
Using the Features APIcgmonroe
 
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.cgmonroe
 
Intro to CSS Selectors in Drupal
Intro to CSS Selectors in DrupalIntro to CSS Selectors in Drupal
Intro to CSS Selectors in Drupalcgmonroe
 
Drupal Workflow Concepts
Drupal Workflow ConceptsDrupal Workflow Concepts
Drupal Workflow Conceptscgmonroe
 
TriDUG WebFM Presentation
TriDUG WebFM PresentationTriDUG WebFM Presentation
TriDUG WebFM Presentationcgmonroe
 

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

Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
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.pdfsudhanshuwaghmare1
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
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 CVKhem
 
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...Drew Madelung
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 

Recently uploaded (20)

Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
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
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
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
 
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...
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 

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.