Adventures in Drupal 6
In:
30Nov2007
As soon as we get the Ubercart 1.0 release out the door, we're going to dive into converting the entire project to Drupal 6. Drupal 5 has served us well for over a year now, but many features offered by the major API changes/additions (menu, forms, schema) are just too sweet to miss out on when we start making our own Ubercart sites. I know we'll be taking a beating for at least a couple weeks updating all our modules, but ... well, no "but" - it's just going to hurt. ;)
In anticipation of the update, I've decided to dive into module development in Drupal 6 early. As my pilot project, I've started building out a budget module my wife and I can use to monitor our spending through a Drupal site. I'm hoping other people and organizations will find online budget tracking handy, and I'm betting they'll be happy to use Drupal 6 to do it. (How sweet will it be to be able to enter receipts remotely? Your budget won't get torn to shreds when you go on vacation.) After several hours reading d.o, chatting in IRC, and trying everything until my eyes hurt, I'm starting to feel comfortable with the changes.
So, Drupal 5 module developer... what can you expect when you come to Drupal 6? A lot of new, and a bit of confusing. The documentation is still being fleshed out and arranged, so you should be gracious to those posting it up as you try to find that bit of info you need. Overall, it's been pretty helpful, and there are always plenty of examples in Drupal core for just about anything you'll need to do. You can expect to spend a few hours grokking the changes to the menu and forms APIs, even if you were there to see Jeff's ewoks dance in Barcelona. There's just too much going on for folks familiar with the old systems to grasp all the changes in one go. Also, you can expect to spend plenty of time learning to use the new schema API. Here again, I just opened up as many .install files as I could find in core and went to town trying and retrying my own. Just keep reminding yourself that this really is a huge improvement over the old method (or lack thereof) of creating tables!
A few things to look out for that I wasn't expecting and don't know if they're documented:
- It seems truncating cache_menu no longer does the trick when fooling with your menu hooks to get them right. I've kept the modules page open and disabled/re-enabled the module while working on it. Surely someone can point me to a higher path. 8)
- The sequences table is out and auto_increment (and other DB equivalents) are back in. The schema API lets you specify a column's type as 'serial' and takes care of the rest. I got snagged here on a default value in my schema (was copy/pasting...). As far as I know, you should not specify a default value on a serial column. (At least setting it to 0 is going to give you a nice error when it tries to install.)
- All form builder functions are being passed an argument... the catch all $form_state array. Either I missed this in the update notes or it wasn't yet in the right place, but this had me baffled for a bit till I realized that the first parameter passed to your function when you use drupal_get_form() is always going to be $form_state. You should account for this if you're counting on a form receiving any arguments, like this one from my budget.module:






Comments
#1 In Drupal 6.x latest, module
Submitted by Gábor Hojtsy (not verified) on Fri, 11/30/2007 - 06:53.
In Drupal 6.x latest, module page displays (reloads) themselfs clear the cache due to otherwise appearing bugs in the order of how things are rebuilt and modified in the database. So a refresh on the modules page will do the cache refresh.
#2 Excellent news! I'll update
Submitted by Ryan on Fri, 11/30/2007 - 09:35.
Excellent news! I'll update this evening. Thanks for the heads up.
#3 The first "problem" you
Submitted by Wim Leers (not verified) on Fri, 11/30/2007 - 07:16.
The first "problem" you describe - the clearing of the cache_menu table - can be done like this: add a call to menu_rebuild() in your index.php. pwolanin pointed me to this some time ago, when I was testing Drupal 6 patches that affected menus.
That magical coordinated load function seems very handy to me. Thanks for sharing!
#4 Just reload the module page.
Submitted by chx (not verified) on Fri, 11/30/2007 - 07:24.
Just reload the module page. It now rebuilds the module tables and theme registries on every load. No need to do anything, just reload.
#5 Great writeup and I so look
Submitted by Benjamin Melançon (Agaric Design) (not verified) on Fri, 11/30/2007 - 08:54.
Great writeup and I so look forward to your budget module!
#6 Couple things... 1)
Submitted by Matt Farina (not verified) on Fri, 11/30/2007 - 09:11.
Couple things...
1) node_load does cache the nodes it loads.
2) There is a function in the devel module to clear the menu cache. Though, I'm sure there is a good way to do it without devel module I just don't know it.
#7 Actually, as of this week
Submitted by Jeff Eaton (not verified) on Fri, 11/30/2007 - 10:04.
Actually, as of this week there's now a way to do it in Drupal core -- the admin/settings/performance page has a big CLEAR CACHED DATA button that will rebuild menus, clear cache tables, reset the CSS and JS caches, and rebuild the theme registry in one step.
#8 Thanks for the report, Jeff.
Submitted by Ryan on Fri, 11/30/2007 - 10:10.
Thanks for the report, Jeff. The replies to this post just get better and better.
*cue the dancing ewoks*
#9 I'd completely forgotten
Submitted by NikLP (not verified) on Mon, 12/03/2007 - 16:31.
I'd completely forgotten about the Ewoks. Thank goodness for this post.
Good work as always Ryan
#10 Check out Xero.com. My
Submitted by Bevan (not verified) on Fri, 11/30/2007 - 21:41.
Check out Xero.com. My dream accounting and budgeting app is to have something like Xero running on drupal. Xero has got everything right, except that they run on a proprietary platform (.Net).
#11 This is a glimpse of Xero;
Submitted by Bevan (not verified) on Fri, 11/30/2007 - 22:27.
This is a glimpse of Xero; http://drupal.geek.nz/node/50
#12 "$form_state" is SO not a
Submitted by Guest (not verified) on Mon, 12/03/2007 - 00:26.
"$form_state" is SO not a word.