You are here

function hosting_features_form in Hosting 7.4

Same name and namespace in other branches
  1. 5 hosting.features.inc \hosting_features_form()
  2. 6.2 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.

Parameters

array $form: The built form.

array $form_state: The current form state.

Return value

array A drupal form.

See also

hosting_features_form_submit()

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

File

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

Code

function hosting_features_form($form, &$form_state) {
  $form = array();
  $form['settings'] = array(
    '#type' => 'checkboxes',
    '#title' => 'Settings',
    '#options' => array(
      'dependencies' => 'Display dependencies',
      'roles' => 'Display roles and permissions',
    ),
    '#default_value' => variable_get('hosting_features_form_settings', array()),
    '#weight' => -20,
  );
  $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.'),
  );
  $advanced = array(
    '#type' => 'fieldset',
    '#title' => t('Advanced'),
    '#collapsed' => TRUE,
    '#collapsible' => TRUE,
    '#description' => t('Advanced features require a deep knowledge of Aegir and Drupal to be considered safe, so use at your own risk.'),
  );
  $features = hosting_get_features(TRUE);
  foreach ($features as $feature => $info) {
    $description = $info['description'];
    if ($settings = variable_get('hosting_features_form_settings', FALSE)) {
      if ($settings['dependencies']) {

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

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

        // Add collapsed fieldset listing the feature's permissions assigned per role.
        $role_perms = isset($info['role_permissions']) ? $info['role_permissions'] : FALSE;
        if (is_array($role_perms)) {
          $element = drupal_get_form('hosting_feature_role_perms_table', $role_perms);
          $description .= drupal_render_children($element);
        }
      }
    }

    // Disable checkbox for required features.
    $locked = FALSE;
    if ($info['status'] == HOSTING_FEATURE_REQUIRED) {
      $locked = TRUE;
    }
    elseif (isset($required_by) && $required_by) {
      foreach ($required_by as $mod => $feat) {
        $locked = $features[$feat]['enabled'] ? TRUE : $locked;
      }
    }
    $element = array(
      '#type' => 'checkbox',
      '#title' => check_plain($info['title']),
      '#description' => $description,
      '#default_value' => $info['status'] == HOSTING_FEATURE_REQUIRED ? 1 : hosting_feature($feature),
      '#required' => hosting_feature($feature) == 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;
      }
      elseif ($info['group'] == 'advanced') {
        if (!isset($advanced[$info['package']])) {
          $advanced[$info['package']] = $package;
        }
        $advanced[$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 (isset($info['group']) && $info['group'] == 'required') {
        $required['hosting_feature_' . $feature] = $element;
      }
      elseif (isset($info['group']) && $info['group'] == 'optional') {
        $optional['hosting_feature_' . $feature] = $element;
      }
      elseif (isset($info['group']) && $info['group'] == 'advanced') {
        $advanced['hosting_feature_' . $feature] = $element;
      }
      else {
        $experimental['hosting_feature_' . $feature] = $element;
      }
    }
  }
  $form['required'] = $required;
  $form['optional'] = $optional;
  $form['advanced'] = $advanced;
  $form['experimental'] = $experimental;
  $form['#submit'][] = 'hosting_features_form_submit';
  return system_settings_form($form);
}