Intro To DRUPAL Module Internals<br />Greg Monroe<br />Triangle Drupal Users Group<br />Aug 11, 2011<br />
Skills and Tools<br />A very basic knowledge of PhP (e.g. can kinda follow the basic logic but may not be able to write it...
What we won’t cover<br />Finding modules<br />Downloading modules<br />Installing modules<br />Enabling modules<br />Confi...
What will be covered<br />How Modules work overview<br />Basic module file structure<br />Finding modules<br />The .info f...
How modules work<br />Core finds them via admin/build/module<br />Stores info about them in System DB table<br />Enabling ...
Some Hook Fundamentals<br />There are many hooks from many sources but a good starting place is:http://api.drupal.org/api/...
Useful Module Splunking Hooks<br />Hook_help<br />Hook_menu<br />Hook_block<br />Hook_theme<br />Hook_perm<br />Hook_views...
Module File Structure<br />All module files live under a common directory, who’s name is the module “basename”.  E.g., Org...
An Example of Module files<br />The Organic Group Module<br />
Finding a Module<br />Finding a module that is creating some page or block from the displayed page is hard… and beyond thi...
Where’s Wald..err..the Module<br />Modules can live many places… but by convention they generally live under one of three ...
Module Files<br />Required:<br />	<basename>.info<basename>.module<br />Recommended:<br />	README(.txt)LICENSE(.txt)<basen...
The .info file<br />The module.info file contains the basic description of the module.<br />
The .Module File<br />The <Basename>.module file contains the core code for the module and generally all the hooks we’re i...
Finding Hooks<br />With the .module file in an editor:<br />If your editor show functions, just look for the _<hook name> ...
Hook_Help<br />Notes:<br />Supplies text for Drupal<br />Advanced help system<br />Case statements<br />  – URL help appli...
Hook_Menu<br />Notes:<br />Defines URLs (as menu<br />items or just pages) for “pages” the module <br />creates<br />$item...
Hook_Block<br />Notes:<br />If ($op == list) section<br />- Defines blocks this <br />   module adds<br />‘info’ array key...
Hook_Theme<br />Notes:<br />‘<basename>_xxx’ keys<br /> - These define the theme   “hooks” for this module<br />‘arguments...
Hook_Perm<br />Notes:<br />Defines the permissions this<br />module uses.<br />Note that many modules use<br />PhP constan...
Hook_views_api<br />If you find this hook, you know that this module supports views and might be supplying blocks and page...
Questions / More Info<br />Pro Drupal Development is the “bible”<br />Drupal API site has lots of docs on hook<br />Drupal...
Upcoming SlideShare
Loading in …5
×

Intro to Drupal Module Internals

1,996 views
1,907 views

Published on

OK, you've installed that new Drupal module but the documentation is skimpy.. what now?

You don't need to be a coder to suss out the secrets within if you know a little about key module internals.

This TriDUG presentation was designed to help Drupal "power users" (or people aspiring to be) understand how to find information from the code (without knowing a lot of Ph). This includes things like: Menu/Page URLs, Blocks, Themable items, and the like.

Note: Sorry the finding views part is skimpy in the presentation... time limitation kept me from fleshing this out more.

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,996
On SlideShare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
31
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Intro to Drupal Module Internals

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

×