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

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfOrbitshub
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Orbitshub
 
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 FMESafe Software
 
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, ...apidays
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Victor Rentea
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Victor Rentea
 
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 2024The Digital Insurer
 
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...Jeffrey Haguewood
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...apidays
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfOverkill Security
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Angeliki Cooney
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 

Recently uploaded (20)

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
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
 
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, ...
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
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
 
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...
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdf
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
+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...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 

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.