Features, a neat module to embed stuff in code. Keeping stuff in the database brings all sorts of ugly deployment and performance issues, so we avoid like the proverbial plague.
I'm an experienced Drupal developer. I've been embedding stuff in code for ages now. Views, Panel pages, ImageCache presets, even putting CCK content type exports in to
hook_install() implementations just to try to keep stuff in code. Many of you are probably in the same boat. Keeping stuff in the database brings all sorts of ugly deployment and performance issues, so we avoid like the proverbial plague.
Now, just in case you've spent the last year on the planet Zog and have only just returned, there's a neat module these days called Features which supposedly does all this for you.
After months of procrastinating over when/if to take plunge in to Drupal development with this whizzy new module, I finally did it this week. And wow. Just... wow.
So what took me so long? Well, mainly it was the fear of another steep learning curve and me already working 10 hour days as it is! Knowing how much of a PITA it is to do all this manually, I naturally assumed Features would be horribly complicated and I sincerely could not face learning anything under the present workload, so I put it off and put it off and put it off...
Until I had a fresh project that I figured would really benefit from the Features model. I installed it and off I went.
I had already created a Yahoo! Answers style element in Drupal for my client. It felt like the perfect starting point for a nice new Features-based module. It was basically made up of some content types and views. The content types had some fancy CCK stuff going on (mainly using the excellent Nodereference URL) and the Views had some fancy display settings (courtesy of Views Attach and Views Slideshow), but essentially there wasn't much to it after the configuration.
Time to turn it in to a module. Hmmmm. Deep breath:
So, where is Features hiding?
Site building -> Features... that feels like a good starting point.
Name, description, version, all seems obvious enough. Mkaaay...
URL of update XML? I'll ignore that, it's not compulsory and I have no idea what it should be...
Add components? A drop-down list... now this looks interesting...
Content types, I got some of those... Question and Answer (ticky tick tick).
That's when I nearly wet myself. OMFG, it just auto-added all the module dependencies! How cool is that?!
Views, I got some of those too...
questions and answers (again! tickety tickety tick those checkboxes).
HA! It did it again! views_slideshow and views_attach added as dependencies automatically. Awesome!!
Hmmm, it didn't pick up the core Statistics module. I need that for reads.
No matter, there's a "Dependencies" option.
And yes, it's a list of enabled modules. Hurrah! Ticky tick Statistics.
Yup, I do believe that's it. Click the "Download feature" button, I guess? A packaged module! Content types, Views and all dependencies. Install it back on the site and bingo, there it is on the currently installed Features list. That's it, I'm finished! That took, oh, 2 minutes?
Intuitive? Hell yeah! I certainly need not have been so concerned about learning curve. Actually Features is easy peasy - far easier than I ever imagined it could be. In fact, I can honestly say you no longer need to have a clue about Drupal development to make Drupal modules*. My two-year-old could build a module with this! This is the coolest thing since the bread slicing machine, seriously.
* But you will need the Features module, naturally.
Then there's the other things you can do. There's drush integration (for command line Features module creation and updating), there's the Strongarm module (for exporting variables, amongst other things), there's CTools integration for creating exportable objects, etc. etc. Just read the project page.
But even if you don't want to get in to all that. Even if you've simply made some sort of simple application, you think it's worth sharing and you don't want to have to build it all over if you need it again. Make it a Feature! You don't need to know a line of code. If you know your way around the Drupal UI well enough to create content types and Views, and you have the necessary bodily appendages to allow you to wield a pointing device and tick boxes, you can make a Drupal module.
The only thing I really miss is the ability to bundle user roles and their related permissions settings with my Features module. (Or at least, I think I miss it? Maybe you can already do this and I've missed the option.)
Before I sign off, quick note on sharing Features-based modules. I think I'm right in saying you can't just stick them on Drupal.org. Or people aren't doing anyway, even though thinking about it, I don't see why not if you have CVS access. Perhaps someone can expand on that in the comments?
Anyway, if you want to put your modules on a Features community server, there are several community servers about and, if you're feeling really adventurous, you can host your own community server. By the way, that's where "URL of update XML" comes in. Remember I didn't know what to do with it? It's simply the URL of the community server your module is hosted by, so the core Update Status module knows where to look for update information.