You are here

function variable_realm_select_variables_form_submit in Variable 7.2

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

Select variables for realm.

File

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

Code

function variable_realm_select_variables_form_submit($form, &$form_state) {

  // Get realm name and current list of variables.
  $realm_name = $form_state['values']['realm_name'];
  $controller = variable_realm_controller($realm_name);
  $old_variables = $controller
    ->getEnabledVariables();

  // Get main variable names
  $variables = $form_state['values']['variables'];
  unset($variables['variables__active_tab']);
  $variables = array_keys(array_filter($variables));

  // Translate variable names
  foreach ($variables as $index => $name) {
    $variables[$index] = str_replace(array(
      '<',
      '>',
    ), array(
      '[',
      ']',
    ), $name);
  }

  // Hook for modules to alter this variable list.
  drupal_alter('variable_realm_variable_list', $variables, $realm_name);

  // And save the list to a variable.
  $controller
    ->setRealmVariable('list', $variables);

  // Spawn multiple variables and translate into actual variables
  $new_list = variable_children($variables);

  // Delete variables from realm that are not in the new list.
  $old_list = variable_children($old_variables);
  foreach (array_diff($old_list, $new_list) as $name) {
    $controller
      ->deleteVariable($name);
    drupal_set_message(t('Deleted existing values of %name from realm variables.', array(
      '%name' => $name,
    )));
  }
}