The features module enables the capture and management of features in Drupal. A feature is a collection of Drupal entities which taken together satisfy a certain use-case. Features provides a UI and API for taking different site building components from modules with exportables and bundling them together in a single feature module. A feature module is like any other Drupal module except that it declares its components (e.g. views, contexts, CCK fields, etc.) in its .info file so that it can be checked, updated, or reverted programmatically. Thus, technically, an exported Feature is a Drupal module, it has a .info file and a .module file (along with some .inc files matching the components of the feature).
Examples of features might be:
- A blog
- A pressroom
- An image gallery
- An e-commerce t-shirt store
In Drupal 7, site settings and configuration are made exportable using the Chaos tool suite (ctools). Features module offers a well-known method of bundling these exportables in a new downloadable feature module. There are some useful Drush commands for managing Features. Read more about the drush commands Features offers.
Features takes advantage of the powerful exportables concept pioneered by Views to allow all of your feature’s site building to live in code (exported views, contexts, imagecache presets, node types, etc.) but also be overridden and in the database. This allows you to take advantage of version control to collaborate and share your site building work, and to also use standard Drupal site building UIs to take the next steps in improving your features. Here is an overview of current support in Features for other modules that have exportables:
- Content Types
- Text formats
- Image styles
- User roles and permissions
- System vaiables (Strongarm)
- Node queues
- Boxes (blocks)
- Nodes (content)
- Commerce products
- Many more…
Modifying, updating and reverting Features
Once you’ve got a feature installed and running, chances are that you’ll want to fiddle and change in some of its settings. The Features module will notice any changes made to a component of any features and signal this with an Overridden state on the Features administration page. The Features module will allow an administrator to inspect the changes, revert to the original state and also to update the feature by applying the new changes to it. Here’s how it works:
- The View option displays a crude list of all the settings in the feature. If you have the Diff module installed, you can also use the Compare option to see what has been changed in a more convenient way
- The Revert option presents a list of the changed components in the feature, allowing the administrator to uncheck any of them before reverting the rest to its original state
- The Update option is identical to the Create feature page, with the exception that fields and component list is pre-populated
This operation changes your site configuration to match up with the definitions in the feature module code. In some cases (e.g. views), the revert operation will delete the respective configuration in the database, so the system will instead use the default configuration that is defined in the feature module’s code.
The update operation will produce a modified version of your feature module, which matches up with the configuration found in the database. What happens with this modified code, depends on whether you do this with drush or with the web-based interface. If you update the feature via drush, the modified code will replace your existing feature module in the filesystem.
The recreate button in the web-based administration interface is the equivalent to update. However, the modified code will be provided for download as a .tar archive, instead of overwriting the existing feature module. It is up to the site builder to manually unzip and re-upload the modified module, replacing the original.
Tips for creating features
- Namespace, you’re naming a module so pick a unique (machine) name. Modules can conflict, so prefix your feature, i.e. feature_blog instead of blog (will conflict if there is already a module with the name blog
- Take a close look at the variabales you want to be exported to your feature
- Take care of any dependencies