Scared Of Features? Don't Be!

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.
Hmmm, no Features installed yet, that figures.
Create Feature? Probably.
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?
Wow.

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, I put my module on mig5's Features community server, here:
http://community.featureservers.org/project/answers

You can too. 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.

what is the difference

what is the difference between drush make and features ?

I had the same problem with

I had the same problem with features, and it seems that i was totally wrong!! Thanks for sharing you experience :). Gonna share some features ;)

To install a feature on a

To install a feature on a site, should those modules where feature is depending on, download and install modules manually ?

Yes

You need to go and install all dependencies for *any* Drupal module (it's not a Features thing, it's a Drupal core thing) before you will be able to enable the module requiring them. The enable check-box will be greyed out until all the dependencies are satisfied (downloaded to a valid modules directory).

I find it good practice to always enable the modules which are dependencies PRIOR TO enabling the module with dependencies, as the install order is arbitrary and installation may fail in an ugly way if any of the dependencies were required by the installation scripts and weren't yet available.

actually...

You only need to download the required modules. As long as they are available on the server, Drupal will detect that they are not enabled and do so for you, whether using admin/build/modules or "drush enable".

And since features, for the most part, only uses CCK, Views, panels, and their addons, you don't have to worry much about letting it install them in any order.

Nope

While that may be true of Features-based modules, as a general rule it's not strictly true. You should enable dependencies first (even though that's not necessary according to the docs). Potential issue described in more detail here:
http://drupal.org/node/365098

permissions

Nice writeup Greg -- nice to see you go from asking questions on Twitter to building/sharing features :)

On permissions -- you can export permissions w/ their associated roles. It's one of the drop-down options in features. I'd suggest not doing that however on something you share publically as the roles on your site + permissions might not match up with whoever else will be using it.

Roles too

That's good to know - at least you can pre-configure "authenticated" and "anonymous". It would be nice to be able to bundle roles too.

agenttrickard's Secure Permissions suggestion looks good for that though:
http://drupal.org/project/secure_permissions

Need Better Tar Support

I've tried to use it but I've given up for now due to this bug:

unable to extract tarball with tar
http://drupal.org/node/522794

Ubuntu

Ubuntu doesn't have a problem as well.

Odd

No such issue with Fedora. It works fine.

Good writeup

StrongArm only handles the variables table so it won't help with permissions, other dependencies, etc. And the content type integration in Features is still not complete.. hopefully after I finish this patch for CCK there'll be a better solution for handling them, then some cleanup work on Features to make it a more straight-forward module builder and it could be golden ;-)

The only thing I really miss

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.)

The Secure Permissions module does this part, but not with Features integration.

Nice write-up. I've played a

Nice write-up. I've played a bit with Features but I'm still a little scared of it. Like what if your Feature needs a module that does not provide exportables? Is that where strongarm comes in? I admit I haven't done enough research on this topic. But, for example, a wiki Feature may contain CCK and Views, but would also contain Markdown and Freelinking and Diff and their various settings. I guess I could just set those in mymodule_install()?

Oh and thanks for that Answers feature!

Strongarm... and the *.module file

Strongarm is used with features to export any variable in the system. Strongarm is required if you want to save Node Type settings, like comments and attachments, so it's pretty much essential to use it for any feature you are building.

Luckily, it adds a list of all variables with simple checkboxes just like everything else, so its easy to scroll through and select the variables you want to save with your feature.

On another note...
the created feature.module file is free to edit at will, add any other hooks you want in there. Features will preserve whatever is there when you re-create the feature. You are also free to add a feature.install file to the package.

Dependencies

Thanks - re: other modules, if Features doesn't pick them up automatically, you can manually add them with the Dependencies option when creating a Features-based module. I guess you'd want to encapsulate the Input Filter settings as well though? That may require you rolling up your sleeves and doing some hook_install() magic right now, but I don't know. Perhaps Strongarm would help? I haven't checked it out yet.

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <blockquote>
  • Lines and paragraphs break automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.