You are here

function openid_connect_admin_form_submit in OpenID Connect / OAuth client 7

Submit handler for openid_connect_admin_form.

File

includes/openid_connect.admin.inc, line 116
Administrative UI and functions for the OpenID Connect module.

Code

function openid_connect_admin_form_submit($form, &$form_state) {
  $enabled_clients = $form_state['values']['openid_connect_clients_enabled'];
  $enabled_clients = array_filter($enabled_clients);
  variable_set('openid_connect_clients_enabled', $enabled_clients);
  foreach ($enabled_clients as $client_name) {

    // Give the client a chance to modify the submitted values.
    $client = openid_connect_get_client($client_name);
    $fake_form = $form['clients'][$client_name];
    $fake_form_state = array(
      'values' => $form_state['values']['clients'][$client_name],
    );
    $client
      ->settingsFormSubmit($fake_form, $fake_form_state);

    // Save the settings.
    variable_set('openid_connect_client_' . $client_name, $fake_form_state['values']);
  }
  $claims = array();
  foreach ($form_state['values']['userinfo_mapping'] as $variable => $claim) {
    if (!empty($claim)) {
      $claims[] = $claim;
      variable_set($variable, $claim);
    }
    else {
      variable_del($variable);
    }
  }
  if (!empty($claims)) {
    variable_set('openid_connect_userinfo_mapping_claims', $claims);
  }
  else {
    variable_del('openid_connect_userinfo_mapping_claims');
  }
  $default_enabled = array(
    'openid_connect_always_save_userinfo',
    'openid_connect_user_pictures',
  );
  foreach ($default_enabled as $variable) {
    if (isset($form_state['values'][$variable])) {
      variable_set($variable, $form_state['values'][$variable]);
    }
  }
}