You are here

function hosting_features_form in Hosting 6.2

Same name and namespace in other branches
  1. 5 hosting.features.inc \hosting_features_form()
  2. 7.4 hosting.features.inc \hosting_features_form()
  3. 7.3 hosting.features.inc \hosting_features_form()

The Hosting features form.

This returns a form with any known Hosting features grouped and listed. It allows administrators to enable or disable the features.

Return value

A drupal form.

See also

hosting_features_form_submit()

1 string reference to 'hosting_features_form'
hosting_menu in ./hosting.module
Implementation of hook_menu().

File

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

Code

function hosting_features_form() {
  $optional = array(
    '#type' => 'fieldset',
    '#title' => t('Optional system features'),
    '#description' => t('You may choose any of the additional system features from the list below.'),
    '#collapsible' => FALSE,
  );
  $required = array(
    '#type' => 'fieldset',
    '#title' => t('Required system features'),
    '#collapsed' => TRUE,
    '#collapsible' => TRUE,
    '#weight' => -10,
    '#description' => t("These features are central to Aegir's functionality, and thus cannot be disabled."),
  );
  $experimental = array(
    '#type' => 'fieldset',
    '#title' => t('Experimental'),
    '#collapsed' => TRUE,
    '#collapsible' => TRUE,
    '#description' => t('Features marked experimental have not been completed to a satisfactory level to be considered production ready, so use at your own risk.'),
  );
  $features = hosting_get_features(TRUE);
  foreach ($features as $feature => $info) {
    $description = $info['description'];

    // Gather dependencies and their statuses
    $depends_on = isset($info['dependencies']['features']) ? $info['dependencies']['features'] : FALSE;
    if ($depends_on) {
      $description .= theme('hosting_feature_dependencies', $depends_on, 'Depends on', $features);
    }

    // Gather relying features and their statuses
    $required_by = isset($info['dependencies']['reverse']) ? $info['dependencies']['reverse'] : FALSE;
    if ($required_by) {
      $description .= theme('hosting_feature_dependencies', $required_by, 'Required by', $features);
    }

    // Disable checkbox for required features.
    $locked = FALSE;
    if ($info['status'] == HOSTING_FEATURE_REQUIRED) {
      $locked = TRUE;
    }
    elseif ($required_by) {
      foreach ($required_by as $mod => $feat) {
        $locked = $features[$feat]['enabled'] ? TRUE : $locked;
      }
    }
    $element = array(
      '#type' => 'checkbox',
      '#title' => $info['title'],
      '#description' => $description,
      '#default_value' => $info['status'] == HOSTING_FEATURE_REQUIRED ? HOSTING_FEATURE_REQUIRED : hosting_feature($feature),
      '#required' => $info['status'] == HOSTING_FEATURE_REQUIRED,
      '#disabled' => $locked,
    );

    // Add another fieldset based on contrib module package.
    $package = FALSE;
    if ($info['package'] != 'Hosting') {
      $package = array(
        '#type' => 'fieldset',
        '#title' => $info['package'],
        '#collapsed' => FALSE,
        '#collapsible' => TRUE,
      );
    }
    if ($package) {
      if ($info['group'] == 'required') {
        if (!isset($required[$info['package']])) {
          $required[$info['package']] = $package;
        }
        $required[$info['package']]['hosting_feature_' . $feature] = $element;
      }
      elseif ($info['group'] == 'optional') {
        if (!isset($optional[$info['package']])) {
          $optional[$info['package']] = $package;
        }
        $optional[$info['package']]['hosting_feature_' . $feature] = $element;
      }
      else {
        if (!isset($experimental[$info['package']])) {
          $experimental[$info['package']] = $package;
        }
        $experimental[$info['package']]['hosting_feature_' . $feature] = $element;
      }
    }
    else {
      if ($info['group'] == 'required') {
        $required['hosting_feature_' . $feature] = $element;
      }
      elseif ($info['group'] == 'optional') {
        $optional['hosting_feature_' . $feature] = $element;
      }
      else {
        $experimental['hosting_feature_' . $feature] = $element;
      }
    }
  }
  $form['required'] = $required;
  $form['optional'] = $optional;
  $form['experimental'] = $experimental;
  $form['#submit'][] = 'hosting_features_form_submit';
  return system_settings_form($form);
}