You are here

function hosting_quota_form_alter in Hosting 6.2

Same name and namespace in other branches
  1. 7.4 quota/hosting_quota.module \hosting_quota_form_alter()
  2. 7.3 quota/hosting_quota.module \hosting_quota_form_alter()

Insert edit controls for the hosting quotas into the client edit form

File

quota/hosting_quota.module, line 299
Implement quota's for the resource used by client.

Code

function hosting_quota_form_alter(&$form, $form_state, $form_id) {
  if (user_access('edit all quotas') && isset($form['type']) && isset($form['#node']) && 'client_node_form' == $form_id) {
    $node = $form['#node'];
    if (!($quota_info = $node->quota)) {
      $quota_info = module_invoke_all('hosting_quota_resource');
    }
    $form['quota'] = array(
      '#type' => 'fieldset',
      '#title' => t('Client quota settings'),
      '#access' => user_access('edit all quotas'),
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
    );
    foreach ($quota_info as $resource => $quota) {
      if (!$quota['limit']) {
        $quota['limit'] = variable_get("hosting_quota_default_{$resource}", 0);
      }
      $form['quota']['quota-' . $resource] = array(
        '#title' => $quota['title'],
        '#description' => $quota['description'],
        '#type' => 'textfield',
        '#default_value' => $quota ? $quota['limit'] : 0,
      );

      // Validate that a number was submitted for the quota
      $form['#validate'][] = 'hosting_quota_numeric_value';
    }
  }
}