How Drupal Works: An Architect's Overview—Notes
Through the Lullabot podcasts, Jeff Eaton (and the other Lullabots) gave me my introduction to Drupal. I'm not sure how he packs his Drupal chatter with so much information and hilarity all at the same time, but the combination is definitely one of the things that got me hooked on Drupal.
So reading quotes from this presentation as they popped up on Twitter is one of the things that made me most angry at the ash cloud. But it is now up online (!) thanks to the amazing DCSF organizers (double !).
Here are my notes. I've removed most of the funny (and got tired at the end), so you should really watch the real thing.
About Drupal
- Drupal is modular. That means if you take out all modules, then its just a set of APIs that don't do anything on their own.
- Drupal is also event-driven. This fact can be masked to OO programmers by the fact that it is written in procedural PHP. But magically named PHP functions called hooks are the way of interacting with events as they are fired off. Your modules are listening for things to happen and doing something when those things happen. The idea of events and listeners using the hook system is fundamental.
- Drupal is skinnable. Everything that a module generates that is going to be seen by an end user should be passed through the theme layer, which is separate from the plugin module that deal with data. This way, they can be transformed into XML, HTML, whatever, through the theme layer. Keeping in mind why drupal has this separation is important. The moment you think about creating a mobile version of your site, you will discover all the places where you forgot the hard coded HTML that you put in your module.
- Drupal is organic. Drupal grows and evolves without a central roadmap. People complain about the way something works, and either someone else changes it for them or they try and change it themselves. It's worked pretty well, but there are downsides. For instance, there are three separate queue implementations that basically do the same thing.
API layer
Menu API
Database Abstraction
Sits there and allows us to make database queries against any database that someone has written a driver for. In Drupal 7, this gets easier since we're using PDO, a standard PHP library.
Session Handling
Output Filtering
Caching
Batch Processing
Module system
Update system
Allows us to keep track of which schema pieces have fallen out of sync with the module code.
Unicode utilities
- File storage
- Locale & Language
- Themeing (Rendering)
- Forms & Processing
- Image Manipulation
- Email handling
- XMLRPC
Page Request Process
- Someone fires a request to your webserver. They might get a cookie if they've already logged into the site.
- The server gets the request. It goes to .htaccess which says everything should go to index.php
- index.php loads the APIs and gets them ready to handle the request
- The Menu API which was loaded looks up the paths that different modules have registered that they handle.
- The module gets the request and fires hooks to see whether any module wants to help while it's building the page.
- The module returns some info back to the menu system.
- If the everything looks good, it figures out which theme is active and hands off the raw data to the theme layer.
- That gets kicked back to Drupal.
- That gets kicked back to the web server, which kicks it back to the user.
Drupalisms
Hooks
Info Arrays
Drupal uses giant nested arrays to pass information around. You can stick anything in arrays, so you have to look at the API docs to figure out the different structures of the arrays in the APIs.
Callbacks
In an array, you stick a PHP function name in specific places. When the array is being processed, the function will be called.
Renderables
Alter Hooks
The payoff for all the crazy array stuff. Drupal asks if anyone wants to change these arrays before they get fully rendered. It allows you to customize the guts of how other modules work without messing with their code.