Module development <b>tutorial</b>: pants.module

899 views
822 views

Published on

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
899
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
6
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Module development <b>tutorial</b>: pants.module

  1. 1. Module development tutorial: DrupalCon Brussels September 22, 2006 pants.module
  2. 2. Pants? What? Why? We’re gonna learn module development by example We all own pants We all wear pants (sometimes) pants: off
  3. 3. Pants module history This is Andy Smith. Andy is wearing pants (but not a shirt) Andy wrote the first pants.module pants: ON
  4. 4. Feature Requirements Track User Pants status Display current status on profile page Allow users to update their “pants status” Show a block of recent pants updates Allow pants updates via XML-RPC
  5. 5. Check drupal.org for existing similar modules If so, contact the module maintainer - collaborate! First Steps Check groups.drupal.org for similar areas of interest Read: http://drupal.org/ contributors-guide
  6. 6. We need some files: pants.info Let’s get pants.install started! pants.module We need some code No need for pants
  7. 7. pants.info ; $Id$ name = Pants description = Tracks pants status for users.
  8. 8. pants.install Implement table creation per-type. Ideally support MySQL & Pgsql Include any updates by implementing pants_update_N
  9. 9. pants.module Let’s get ready for pants.
  10. 10. helper functions By convention “private” helper functions are prefixed by “_<module>” Modules with lots of helpers can use separate “.inc” files to reduce RAM usage. Higher granularity => Better reuse.
  11. 11. hook_menu Drupal’s menu system is multipurpose. It: registers URL-based callbacks (REST) populates navigation menus serves as highlevel access control
  12. 12. hook_user Several options implemented: “load”: get pants status “insert” / “update”: set pants status “view” : show pants status on profile page
  13. 13. User Edit
  14. 14. User View
  15. 15. hook_block Again: multiple “modes” for hook_block “list”: used to show available blocks “view”: called with $delta to display an individual block
  16. 16. Themeable functions Allow themers to override your markup Good idea anytime you’re including raw HTML in your code
  17. 17. Once more with AJAX! $(document).ready( function() { // Get Drupal basePath var path = Drupal.settings.pants.basePath; Drupal 5.0 features jQuery in $("a#pants").click( function() { core $.get(path + "pants/change", function(result) { $(".pants-status").html(result).fadeIn("slow"); jQuery makes JS/AJAX fun! } ); return false; }); });
  18. 18. Pants block with AJAX
  19. 19. Pants Blocks
  20. 20. hook_xmlrpc Allows you to expose callbacks over XML-RPC Re-use core functionality Change pants status from: Desktop Applications Other Sites
  21. 21. http://www.nopantsday.com/ Pants http://term.ie/p/browser/ drupal_pants/ References http://en.wikipedia.org/wiki/ Pants
  22. 22. http://api.drupal.org/ http://groups.drupal.org/ Developer irc://irc.freenode.net/#drupal References http://drupal.org/contributors- guide http://drupal.org/update/ modules
  23. 23. Thanks! James Walker Bryght Guy mailto/xmpp : james@bryght.com http://walkah.net/ pants: off

×