You are here

function hosting_features_enable in Hosting 7.4

Same name and namespace in other branches
  1. 7.3 hosting.features.inc \hosting_features_enable()

Enable one or more Hosting features.

Parameters

bool $rebuild: Rebuild caches afterwards, default TRUE.

bool $enable: Also enable the Drupal module, default TRUE.

2 calls to hosting_features_enable()
hosting_features_form_submit in ./hosting.features.inc
Submit callback for the Hosting features form.
hosting_modules_enabled in ./hosting.module
Implements hook_modules_enabled().

File

./hosting.features.inc, line 401
Include for functionality related to Hosting module features.

Code

function hosting_features_enable($features, $rebuild = TRUE, $enable = TRUE) {
  if (count($features)) {
    include_once 'includes/install.inc';
    $all_features = hosting_get_features();
    $titles = array();
    foreach ($features as $feature) {
      $titles[] = $all_features[$feature]['title'];
    }
    drupal_set_message(t("Enabling %feature feature!plural.", array(
      '%feature' => implode(", ", $titles),
      '!plural' => count($features) > 1 ? 's' : '',
    )));
    foreach ($features as $module => $feature) {
      variable_set('hosting_feature_' . $feature, HOSTING_FEATURE_ENABLED);
      if ($enable) {
        $success = module_enable(array(
          $module,
        ));
        if (!$success) {
          variable_set('hosting_feature_' . $feature, HOSTING_FEATURE_DISABLED);
          $module_data = system_rebuild_module_data();
          $missing = array_keys(array_diff_key($module_data[$module]->requires, $module_data));
          drupal_set_message(t("An error occurred enabling the `:feature` feature. Missing dependencies: :missing.", array(
            ':feature' => $feature,
            ':missing' => implode(', ', $missing),
          )), 'error');
        }
      }
      if (isset($all_features[$feature]['enable']) && function_exists($callback = $all_features[$feature]['enable'])) {
        $callback();
      }
      $role_perms = isset($all_features[$feature]['role_permissions']) ? $all_features[$feature]['role_permissions'] : array();

      // Make sure the permission exists before adding it.
      $modules = user_permission_get_modules();
      foreach ($role_perms as $role => $perms) {
        foreach ($perms as $i => $permission) {
          if (!isset($modules[$permission])) {
            unset($role_perms[$role][$i]);
          }
        }
      }
      hosting_add_permissions($module, $role_perms);
    }
    if ($rebuild) {
      hosting_feature_rebuild_caches($features);
    }
  }
}