Notes on Drupal Features

John Gould print image of Ornithorhynchus anatinus (platypus) and drupal.  From wikipedia.

One of the difficulties of keeping a Drupal website completely in version control, is that a lot of the configuration is stored in the database. Each change you make to a site via clicking and saving on a site administration page is saved in the database. It is difficult to keep a history of these changes without writing the entire database to a file and then checking that into version control. But you don't want to commit an entire database into git. This is where the Features module comes into play. It helps separate the site's configuration in the database from the site's content.

The Features module allows you to export configuration options from the database into a new module. Then you can check this new module into version control and keep track of the history of changes, and keep backups of a site's configuration that is separated from the site's content and database.

Features Concepts

Exporting Features

Exporting a feature is the processing of exporting a configuration option (or a series of options) from the database and saving them as a features module. Let's say you are using Bartik (or another theme that utilizes the color module to allow you to customize a site's colorscheme.) and you change the background color of the site. When you make this change via the web interface, the configuration change is saved in the database. To export this change as a feature, you click on admin/structure/features/create.

Create a name and description for your new feature, such as "Major Ursa Bartik Colors" and "Color scheme for Bartik theme used on Major Ursa".

Next under Edit Components, select Strongarm: variable. Then select "color_bartik_palette" and perhaps "color_bartik_stylesheets". Then click on the Download Feature button.

This will download a new module to your desktop with the configuration options saved as a features module. This is only step one. Next you will need to upload this new module back up to your website and enable. Once the module is enabled, the configuration is being run from code from the module, not from a configuration option in the database. This is known, confusingly enough, as reverting a feature.


Revert a Feature

To revert a feature is to take the configuration options that are written in a custom feature module and override the database configuration.

Revert a feature with drush

drush features-revert  mu_bartik_theme

The above code would read the configuration options from the code in the mu_bartik_theme and overwrite the current configuration in the database.

Override a Feature

To override a feature, means to take the configuration that is currently in the database and use those options to override the previous custom feature module you created. This basically updates the old feature module with what is currently live on the site and in the database. Then you will be able to download an updated feature module and can commit this new change to your git repository so you have a history of site changes, upload the changed feature module mu_bartik_theme to your site and (ahem revert the change again).

Here's the drush command to override a feature

drush features-override mu_bartik_theme

Features Recap

  • Export Feature: means to export a feature from your site into a module.
  • Revert Feature: means to use the settings in the feature module.
  • Update Feature: means to take the current settings in the database and update the feature module with them.

Drush Commands

drush command shortcut description
drush features-list fl list all features defined for site
drush features-diff fd diff of default and overridden state
drush features-update fu update a feature
drush features-update-all fu-all or fua update all features
drush features-revert fr revert a feature
drush features-revert-all fr-all or fra revert all features