You are here

function hosting_quota_form_alter in Hostmaster (Aegir) 6

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

File

modules/hosting/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';
    }
  }
}