disable rule or view programmatically on feature enable snippet

* Implementing hook_post_features_enable_feature
function myfeature_post_features_enable_feature($component) {
  // no need to call it for every $component,
  // so we choose 'features_api' which is always present
  // bit of a workaround until http://drupal.org/node/1844566,
  // or is there a better way?
  if ($component == 'features_api') {
    $rules_config = rules_config_load('commerce_checkout_order_email'); // replace with your rules machine name
    $rules_config->active = FALSE;

    // below is taken from http://drupal.org/node/1733808
    // a list of views (their view name) I want to disable
    $viewnames = array(

    // grab list of views that are already disabled
    $views_status = variable_get('views_defaults', array());

    // add our views to be disabled to the list
    foreach ($viewnames as $key => $viewname) {
      $views_status[$viewname] = TRUE;

    // reset the variable with the new list
    variable_set('views_defaults', $views_status);

    // empty cache now
    if (function_exists('views_invalidate_cache')) {


This is the company blog of
Drupal specialist Merge.nl

We are located in Breda (Netherlands) and build websites using Drupal. More about us.

Content on this blog is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Netherlands License.

Creative Commons License

Recent Comments