You are here

function variable_realm_select_variables_form in Variable 7.2

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

Select variables for realm.

1 string reference to 'variable_realm_select_variables_form'
variable_admin_menu in variable_admin/variable_admin.module
Implements hook_menu().

File

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

Code

function variable_realm_select_variables_form($form, &$form_state, $realm_name) {
  $controller = variable_realm_controller($realm_name);
  $current = $controller
    ->getEnabledVariables();
  $optional = $controller
    ->getAvailableVariables();

  // The final list will be the sum of both lists. We may have unknown variables
  // we want to preserve.
  $list = array_unique(array_merge($optional, $current));
  $form['realm_name'] = array(
    '#type' => 'value',
    '#value' => $realm_name,
  );
  $form['message']['select']['#markup'] = '<h3>' . t('Select variables to be set for this realm.') . '</h3>';
  if ($current) {
    $form['message']['current']['#markup'] = '<p>' . t('Currently selected variables are: <em>!variables</em>', array(
      '!variables' => variable_list_name($current),
    )) . '</p>';
  }
  $form['variables'] = array(
    '#type' => 'vertical_tabs',
    '#tree' => TRUE,
  );
  $variable_groups = variable_group_variables($list);
  foreach ($variable_groups as $group => $group_list) {
    $group_info = variable_get_group($group);
    $group_current = array_intersect($group_list, $current);
    $form['variables'][$group] = array(
      '#type' => 'fieldset',
      '#title' => $group_info['title'],
      '#theme' => 'variable_table_select',
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
    );
    foreach ($group_list as $name) {

      // Variable names may clash with form element names, so we need to replace '[' and ']'
      $safename = str_replace(array(
        '[',
        ']',
      ), array(
        '<',
        '>',
      ), $name);
      $form['variables'][$group][$safename] = array(
        '#type' => 'checkbox',
        '#default_value' => in_array($name, $group_current),
        '#variable_name' => $name,
        '#parents' => array(
          'variables',
          $safename,
        ),
      );
    }
  }
  $form['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save configuration'),
  );
  return $form;
}