What is the Drupal features module?
Share with Others
If you are a Drupal developer and are not using the Drupal features module to help with your workflow, you are missing out on a huge opportunity. What kind of opportunity you may ask? How about an opportunity to make your life easier, allow you to develop Drupal websites faster, and provide you with simple ways to version control your exportables (views, cck, panels, variable settings, etc). I am going to give a brief recipe of how I use features in my workflow in hopes that maybe you will get some new ideas (and perhaps send ideas my way as I am always looking to improve the development process).
If you want a complete walk through and introduction to the Features module as well as more information on crafting a Drupal development process. You can check out my 5 Secrets to Becoming a Drupal 7 Ninja Ebook.
If you are interested in a video on the Drupal 7 features module, check out my Drupal 7 Features module introduction.
Step 1 - Features
If you have ever built a website with Views, CCK, or Panels, you may have run into this situation many times. You create something and it works perfectly, then either you, or someone else working on the website changes it and... it's broken. It is not easy to roll back changes made to a view or cck field, since it is just stored in the Drupal database. However, there are a few options. You can choose to risk it and not worry about exporting, you can manually export the view or cck field and then save (or more preferably version control) the contents of the export, or finally, you can use the features module to save you a lot of time and hassle.
The Drupal features module works by allowing you to build a module out of your exportables. It does so with a simple point and click interface (there is also a command line option for those so inclined). Then after you create your module, you download it as a zip file and can do what you want with it.
Now lets go back to the example before, lets say you created a Drupal features module with that view and/or cck field. Then after creating the feature, you dropped it back onto the site in the modules directory and turned it on. Now after the change occurs that breaks the view, you can go into the features administration section and see that your features module has been overridden. In fact, you can dig deeper and look at what parts of the module have been overridden. On top of that, for the really investigative bunch, you can install the diff module and see exactly what has changed on the exported code. Now you can go ahead and revert the changes right from the features administration interface.
Lets also look at another example. Lets say you have your Drupal features module, and now you add additional pieces to your view that you want to keep saved. You can go to the command line, and if you have drush installed, run the following Drush command:
drush fu my_features_module
This will go ahead and update your module. This allows you to integrate easily into version control systems. For example, here would be an example of how I track and keep changes to my features modules (using my version control system of choice, Bazaar).
drush fu my_features_module
bzr add
bzr commit -m "My commit message"
bzr push
Update: My new version control system of choice is Git, here is how that might look:
drush fu my_features_module
git add .
git commit -m "My commit message"
git push
Its as simple as that. Now the features module and all its changes are stored in my version control system. This allows me to go back to any revision of my code with ease. The above example will obviously work with any other version control system with only some minor modifications. I will talk more about drush later in this overview.
Step 2 - Extras (Strongarm, Diff)
The Drupal strongarm module is not necessary, but if you want to store your Drupal variable settings, it is very helpful. Strongarm allows you to export settings that are stored in the Drupal variables table. This can be anything from the website name, website email address, comment settings for one of your content types, and a multitude of other settings. The module may sound intimidating, but it is a really simple and effective way to export and save your settings.
The Drupal Diff module, as mentioned above, lets you see the differences in your exported features code before choosing to revert or update your features module. This is another module that is not necessary but has many useful benefits.
Step 3 - Drush
Drush is a tool that I would not want to live without. To keep this part brief (because I could talk all day on the benefits of using drush), Drush is a tool that allows you to interact with your Drupal websites from the command line. This can perform simple tasks on modules like downloading, installing, disabling, and uninstalling. It can also do things like clear your website cache, and perform actions on your website variables (set, update, and delete).
If you are looking for help with Drush, check out this link - Drush: Getting started
Conclusion
Drupal has many contributed tools that can make a developers life much easier. I encourage you to give them a try and see how much they help your development workflow. I will try to post again in the near future with more specific examples on my development workflow. If you are not using the Drupal Features module or Drush yet, give them a chance, and see how it can aid in your Drupal development.