Code for Contrib: When There's Not a Module for That: Module Development for Site Builders and Themers

Drupal is a powerful and modular system— indeed, much of Drupal's power is in its modules, dynamos of pluggable functionality that can build on Drupal's base system and other modules. This session shows how to add features of your own creation in Drupal 7.

You won't understand everything about module development this hour, or this week, this month, this year, or this decade. The approach in this session is learning how to learn. Not simply, this is how you make a widget (no, really, Drupal has those), but what investigation or resource or secret guild of wizards was needed to gain that knowledge?

You can write a module yourself. All you need to do is create two files with some text. Once we've dispensed with the myth of module making as the difficult domain of die-hard Drupalistas, we will then go well beyond an easy example, and try to make you a die-hard Drupalista!

Attention themers and module devs who want to be cool: We will have a special focus on how themes and modules in Drupal 7 are the bastard children of themes and modules in previous Drupal versions:

  • There's a lot of module goodness in themes, now. You can now use alter hooks of all kinds from theme modules, including the fabulous hook_form_alter().
  • It's easier to do theme things from modules, such as provide preprocess functions.

This is great news for themers (and module developers) who are not prudish about such mixing, and we'll cover these hooks newly available to theme developers.

You can, of course, use alter and other hooks newly available in themes as Drupalistas always have, in modules, and there's no reason not to. In fact, there are many reasons to enhance your theming by writing modules. This gives you portions of code that are easier to re-use between sites, and potentially more tools than you have access to in a theme.

In the context of a couple real examples, we will also cover these APIs:

  • form_alter – if you learn one hook, let this be it. It's just so much fun. And now it has a megalomaniac younger sibling, page_alter
  • menu – this is the power of defining our own pages, among other things
  • database – the new Drupal 7 database abstraction layer, aka DBTNG
  • node – nodeAPI is de-opped in 7 (it is many focused functions instead of one big switchy/twitchy one)
  • field – yeah this is the big D7 deal
  • entity – the big deal API making fields possible, including the Entity API module
  • permissions – using and defining
  • AJAX – enhancing usability with immediate on-page response

The methods and tips in this session will be based on the real work of figuring out how to do specific things with Drupal. Our goal is that you learn more than this session teaches you: How to keep learning about module development from Drupal core, from the Examples project, from contributed modules, and from all the other Drupalistas out there.

Intended Audience
Developers looking to improve their module development processes, to get up to speed on (more of) Drupal 7, or to heckle.

Themers ready to realize that they already know how to make modules whenever they need to.

People with a module they've written and want to make better before contributing.

Anyone serious about learning Drupal 7 module development.

Configurators who have realised they need to write some custom code or fill in some missing pieces to take their project to the next level.

Questions the session will answer

  1. How do I write a module that plays well with Drupal core and other modules? (hint: uses lots of hooks)
  2. How do I make a module is extensible by other modules? (hint: defines its own hooks!)
  3. How do I make my module easy for users and administrators to use and developers to understand? (hint: contextual links, help, coding standards)
  4. How do I know when my module is good enough to ship? Where do I get help making it good enough – and secure enough – to contribute to
  5. How do I learn things that aren't covered in this session? How do I find answers in other people's code?

(NOTE: Attached slides are old, will be updated for this session. See also Using the Power of Modules for Theming.)