You are here

function variable_realm_edit_variables_form in Variable 7.2

Same name and namespace in other branches
  1. 7 variable_realm/variable_realm.form.inc \variable_realm_edit_variables_form()

Edit variables for realm.

1 string reference to 'variable_realm_edit_variables_form'
variable_admin_realm_edit in variable_admin/variable_admin.inc
Edit variables for realm.

File

variable_realm/variable_realm.form.inc, line 84
Administrative forms for variable realms.

Code

function variable_realm_edit_variables_form($form, &$form_state, $realm_name, $realm_key) {
  $controller = variable_realm_controller($realm_name);
  $form['realm_name'] = array(
    '#type' => 'value',
    '#value' => $realm_name,
  );
  $form['realm_key'] = array(
    '#type' => 'value',
    '#value' => $realm_key,
  );
  $options['realm'] = variable_realm($realm_name, $realm_key);
  if ($variable_list = $controller
    ->getEnabledVariables()) {
    $form = variable_base_form($form, $form_state, $variable_list, $options);

    // variable_base_form() adds its own submit handler overriding the default,
    // so we need to add it as a explicit submit callback here.
    $form['#submit'][] = 'variable_realm_edit_variables_form_submit';

    // Group variables by variable group for vertical tabls
    $group_list = array();
    foreach ($variable_list as $variable_name) {
      $variable_info = variable_get_info($variable_name, $options);
      $group = $variable_info['group'];
      $group_list[$group][] = $variable_name;
    }
    $form['variables'] = array(
      '#type' => 'vertical_tabs',
      '#tree' => TRUE,
    );
    foreach ($group_list as $group => $group_variables) {
      $group_info = variable_get_group($group);
      $form['variables'][$group] = array(
        '#type' => 'fieldset',
        '#title' => $group_info['title'],
        '#collapsible' => TRUE,
        '#collapsed' => TRUE,
      );

      // Set form parents for this variable / group.
      $options['form parents'] = array(
        'variables',
        $group,
      );
      $form['variables'][$group] += variable_edit_subform($group_variables, $options);
    }
    $form['actions']['submit'] = array(
      '#type' => 'submit',
      '#value' => t('Save configuration'),
    );
  }
  else {
    $form['message']['#markup'] = '<h3>' . t('No variables have been selected as %realm_name specific.', array(
      '%realm_name' => $controller
        ->getTitle(),
    )) . '</h3>';
  }
  if (!empty($realm_info['select path'])) {
    $form['select']['#markup'] = t('To select variables to be configured, see <a href="!select-url">%realm_name variable settings</a>.', array(
      '%realm_name' => $realm_info['title'],
      '!select-url' => url($realm_info['select path']),
    ));
  }
  return $form;
}