Feature toggle

Component ID

2478851

Component name

Feature toggle

Component type

module

Maintenance status

Development status

Component security advisory coverage

not-covered

Downloads

1224

Component created

Component changed

Component body

From Wikipedia

A feature toggle, (also feature switch, feature flag, feature flipper, conditional feature, etc.) is a technique in software development that attempts to provide an alternative to maintaining multiple source-code branches (known as feature branches).

http://en.wikipedia.org/wiki/Feature_toggle

This module gives non developers ability to show or hide features created & deployed by developers.

How to create a feature:
In settings.php

  $conf['feature_flags'] = array(
    'site_help' => array(
      'name' => 'Example feature to toggle help module',
    ),
    'site_log' => array(
      'name' => 'Example feature to toggle database logging module',
    ),
  );

How to enable/disable a feature:
go to /admin/features/toggle and you will see a form as shown in the screenshot.

How to get the status of a feature in PHP:

module_load_include('inc', 'feature_toggle', 'includes/feature_toggle.api');
$is_help_feature_enabled = feature_toggle_get_status('site_help');
if($is_help_feature_enabled == TRUE){
  //Do something
}

How to get the status of a feature in Javascript:

if(Drupal.settings.ft_enabled_features["site_help"]){
  alert("Yes. site_help Feature is enabled");
}

Hooks that get called when a feature is enabled/disabled:

/**
 * Implements hook_feature_toggle_<feature-name>_enable().
 */
function feature_toggle_example_feature_toggle_site_help_enable() {
  module_enable(array("help"), TRUE);
}

/**
 * Implements hook_feature_toggle_<feature-name>_disable().
 */
function feature_toggle_example_feature_toggle_site_help_disable() {
  module_disable(array("help"), TRUE);
}

For more information look at feature_toggle_example module code at http://cgit.drupalcode.org/feature_toggle/tree/modules/feature_toggle_ex...