20

I have a Feature installed using an Installation Profile. But I always have to go and Revert a particular Component so that it's no longer Overridden (so that, for example, the Feature's Blocks appear). I just wanted to know if I can take this step programmatically using code itself in the Installation Profile.

In the screenshot below, I've shown the component that has to be reverted programmatically (in the screenshot, it's already reverted back so check box is not available).

Screenshot

3
  • I don't have an answer to your question, but I'm willing to bet that if you spend some time in the issue queue, you will find out why it starts as reverted. If there isn't a patch available, atleast you will be closer to understanding where you need to attack the problem.
    – Letharion
    Commented Feb 3, 2012 at 7:57
  • @Letharion - But these are all custom blocks and views developed.
    – Hacker
    Commented Feb 3, 2012 at 8:36
  • By that definition, everything you export would be "custom", so that doesn't make sense to me.
    – Letharion
    Commented Feb 3, 2012 at 10:25

8 Answers 8

20

Here are a few thoughts though on resetting your features programmatically or as add-on install scripts.

You could use Drush to reset the Feature:

drush features-revert [feature name]

Another thought would be to use features_revert() during the install process:

features_revert(array('module' => array('component')));

The Strongarm module could be useful as well to force your Feature to retain its default state I think.

I have to agree with @Letharion in his comment on your OP. I would want to know that other important things aren't being mistakenly modified during the install process.

18

You can revert a single features module with features_revert_module().

features_revert_module('my_feature');
16

Revert ALL components in feature

$feature = features_get_features('my_feature_machine_name');
$components = array_keys($feature->info['features']);
features_revert(array('my_feature_machine_name' => $components));
1
  • 5
    I think features_revert_module('my_module'); does all these steps. Commented Jun 21, 2016 at 17:14
5
features_revert(array('module' => array('component')));

Where 'module' is the name of the specific features module (i.e. the the module generated when you download the feature) and 'component' are the components of those features. So if you just want to revert the fields defined in the feature you can use 'field' for component.

5

Use features_revert() to revert specific components only where the syntax is:

features_revert(array($module => $components));

for example:

features_revert(array('module_name' => array('taxonomy', 'node')));

To revert the whole module (with all its components), then use features_revert_module() instead, for example:

features_revert_module('module_name');

Rules

For rules, this method is much quicker (to revert single rule):

$rule_name = 'my_custom_rule';
if ($rule = rules_config_load($rule_name)) {
  $rule->delete();
}

To revert all rules, it's:

if ($rules = rules_config_load_multiple(FALSE)) {
  foreach($rules as $rule) {
    if ($rule->hasStatus(ENTITY_OVERRIDDEN) && !$rule->hasStatus(ENTITY_FIXED)) {
      $rule->delete();
    }
  }
}

See: Add drush rules-revert [#2474577] | Drupal.org

4

I could solve the issue by using the hook function fe_block_settings_features_revert('basic_site') where fe_block_settings is the hook i.e. the component here and basic_site is the feature/module name.

1
  • 3
    Can you explain a little more? how do you use this function in .profile or .install ?
    – kLezer
    Commented Sep 13, 2012 at 1:34
2

To revert all overridden components of all Features in your Installation Profile, add the following to your .profile file's hook_profile_tasks():

/**
 * Rebuild & Revert all enabled features.
 */
features_rebuild();
features_revert();
0
    /**
     * Reverts all components of a feature.
     */
    function YOURMODULE_helpers_install_features_revert($module, $component = NULL) {
      module_load_include('inc', 'features', 'features.export');
      features_include();
      if (($feature = feature_load($module, TRUE)) && module_exists($module)) {
        $components = array();
        if (is_null($component)) {
          // Forcefully revert all components of a feature.
          foreach (array_keys($feature->info['features']) as $component) {
            if (features_hook($component, 'features_revert')) {
              $components[] = $component;
            }
          }
        }
        else {
          // Use the $component argument of this function.
          $components[] = $component;
        }
        foreach ($components as $component) {
          features_revert(array($module => array($component)));
        }

        drush_print(format_string('Reverted "!module" feature components !components.', array(
          '!module' => $module,
          '!components' => implode(', ', $components),
        )));
      }
      else {
        drush_print(format_string('Unable to revert "!module" feature.', array('!module' => $module)));
      }
    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.