Advertising sustains the DA. Ads are hidden for members. Join today

Access to features

Last updated on
25 October 2017

The aim of this module is to provide the status of some features to modify the site behavior.

Feature Toggle module provides a service named FeatureStatus for this purpose. It is pretty straighforward to accessto the status of any feature:

$status_service = \Drupal::service('feature_toggle.feature_status);
if ($status_service->getStatus('feature_name')) {
  // Do something.
}
else {
  // Do another thing.
}

But this module not only allow to access to feature status from PHP code. It also provides Javascript integration. Here is an example of how to access to them from JS code:

var enabled_features = drupalSettings.feature_toggle.enabled;

if (enabled_features['feature_name']) {
  // Do something.
}
else {
  // Do another thing.
}

Help improve this page

Page status: No known problems

You can: