Revert a Drupal feature during deployment

To revert a features module during deployment, add an update hook and call features_revert with the name of the module and the component you want to revert.

  1. function my_module_update_6001() {
  2. features_revert(array('my_module' => array('panels_mini')));
  3. }

This will revert panels_mini in the features module called "my_module" when you run update.php

You can find the name of the components in the features .info file, as follows:

  1. features[component][] = "name"

So for a mini panel called "my_mini_panel", the .info file would have this line:

  1. features[panels_mini][] = "my_mini_panel"

Now once you have deployed your feature to a new server, you just need to run update.php. The feature will revert to its code version. You would do this if you have changed a feature in your development environment and re-exported to code.

If you liked this, you'll love my book, Master Drupal Module Development.

"..the must have drupal developers book"


This is handy, thanks a lot! Here's a little utility function which makes it a bit easier to completely revert features in an update hook:

Blair Wadman's picture

Thanks for the link to your gist Cameron. Looks good, I'm sure I'll use it. There is also a Drush hook to revert all features, which is handy if you want to revert everything in a deployment/rebuild.


I what location would this code go in?

Blair Wadman's picture

In the .install file of a custom module

Add new comment