The Features module is a vital tool in the Drupal developers and site builders arsenal. It is used to export configuration that is held in the database to a Drupal module, making it easier to version control, deploy and use on other sites. Like the rest of Drupal, you can do everything in the UI but this can be time consuming. Fortunately Features comes with a set of handy Drush commands which should save you valuable time. Let’s go through them one at a time.
Feature update
To update a specific feature, use the feature-update command with the name of the feature you want to update. The alias for feature-update is fu. $ drush fu [feature_name]
To update more than one feature with the same command, add multiple feature names and separate each with space between each name. $ drush fu [feature_name] [feature_name]
An Example of using feature update
A typical example of using feature update is when you are working on an existing feature. You make a configuration change (e.g. change a setting in a content type). The feature will then be overridden, so you need to update the feature to include the configuration change that you have made.
Update all Features
It may be easier to update all features at the same time. You can do this with the feature-update-all command. The alias is fua. To update all features at the same time: $ drush fua
You can exclude some features by passing in their name as an argument. $ drush fua [feature_name]
Feature Revert
You can revert a feature in Drush using the feature-revert command with the name of the feature you want to revert. The alias is fr. $ drush fr [feature_name]
Example of using Feature Revert
You might want to revert a feature if you have made a configuration change that want to undo. For example, you change a setting on a content type but you no longer want that change. As long as the feature has not been updated, or re-exported, yet, you can revert it. This will revert everything in that feature back to the version that exists in code.
Revert all Features
It may be easier to revert all features at the same time. You can do this with the feature-revert-all command. The alias is fra. To revert all features using Drush: $ drush fra
You can exclude some features by passing in their name as an argument. $ drush fra [feature_name]
List all Features
You can list all of the features installed on your site with the features-list command. The alias is fl. To list all the features installed on your site using Drush: $ drush fl
Filter by Status
You can filter the list by using the status option. There are three possible options: enabled, disabled and all. For example, to list all enabled modules: $ drush fl –status=enabled
Export a Feature
You can export a feature and add new components to it with the features-export command. The alias is fe.
$ drush features-export [feature_name] [component1_name] [component2_name] [component3_name]
In order to identify which components to add to a feature, you can use the features-components command. The alias for features-components is fc.
$ drush fc
You will be presented with a list of components. Select one of the components to see which sources are available. You can use those sources in the features-export command.
You can optionally retrieve a list of components that have not yet been exported using the –not-exported option:
$ drush fc –not-exported
An example
You want to export a feature called article and include the article content type and tags taxonomy. Run drush fc and select node. This will return available content types. Article is called node:article. Run drush fc again and select taxonomy. This will return available taxonomy terms. Tags is called taxonomy:tags. To export the feature, run the following command: $ drush fe article node:article taxonomy:tags
You can set the destination directory for the exported feature using the destination option. For example, to repeat the above feature export and set a destination of sites/all/modules/features, use the following command: $ drush fe article node:article taxonomy:tags –destination=sites/all/modules/features
Features Diff
If a feature is overridden, the features-diff command will show the difference between the overridden state and the default state. The alias for features-diff is fd. $ drush fd [feature_name]
Summary of Drush commands for Features
Command | Alias | Arguments/Options |
---|---|---|
feature-update | fu | Arguments: feature : A space delimited list of features Options: --version-set : Specify a version number for the feature. --version-increment : Increment the feature's version number. |
feature-update-all | fua | Arguments: feature_exclude : A space-delimited list of features to exclude from being updated. |
feature-revert | fr | Arguments: feature : A space delimited list of features or feature.component pairs Options: --force : Force revert even if Features assumes components' state are default |
feature-revert-all | fra | Arguments: feature_exclude : A space-delimited list of features to exclude from being reverted Options: --force : Force revert even if Features assumes components' state are default |
features-list | fl | Options:--status : Feature status, can be 'enabled', 'disabled' or 'all' |
features-export | fe | Arguments: feature : Feature name to export components : Patterns of components to include, see features-components for the format of patterns Options: --destination : Destination path (from Drupal root) of the exported feature. Defaults to 'sites/all/modules'. --version-set : Specify a version number for the feature. --version-increment : Increment the feature's version number |
features-components | fc | Arguments: patterns : The features components type to list. Omit this argument to list all components Options: --exported : Show only components that have been exported --not-exported : Show only components that have not been exported |
features-diff | fd | Arguments: feature : The feature in question Options: --ctypes : Comma separated list of component types to limit the output to. Defaults to all types --lines : Generate diffs with |