You are here

function openid_connect_admin_form in OpenID Connect / OAuth client 7

Form builder: Main administrative form.

1 string reference to 'openid_connect_admin_form'
openid_connect_menu in ./openid_connect.module
Implements hook_menu().

File

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

Code

function openid_connect_admin_form($form, &$form_state) {
  $client_plugins = openid_connect_get_plugins();
  $options = array();
  foreach ($client_plugins as $client_plugin) {
    $options[$client_plugin['name']] = $client_plugin['title'];
  }
  $form['#tree'] = TRUE;
  $form['openid_connect_clients_enabled'] = array(
    '#title' => t('Enabled OpenID Connect clients'),
    '#description' => t('Choose enabled OpenID Connect clients.'),
    '#type' => 'checkboxes',
    '#options' => $options,
    '#default_value' => variable_get('openid_connect_clients_enabled', array()),
  );
  foreach ($client_plugins as $client_plugin) {
    $client = openid_connect_get_client($client_plugin['name']);
    $element = 'openid_connect_clients_enabled[' . $client_plugin['name'] . ']';
    $form['clients'][$client_plugin['name']] = array(
      '#title' => $client_plugin['title'],
      '#type' => 'fieldset',
      '#states' => array(
        'visible' => array(
          ':input[name="' . $element . '"]' => array(
            'checked' => TRUE,
          ),
        ),
      ),
    );
    $form['clients'][$client_plugin['name']] += $client
      ->settingsForm();
  }
  $form['openid_connect_always_save_userinfo'] = array(
    '#title' => t('Save user claims on every login'),
    '#description' => t('If disabled, user claims will only be saved when the account is first created.'),
    '#type' => 'checkbox',
    '#default_value' => variable_get('openid_connect_always_save_userinfo', TRUE),
  );
  if (variable_get('user_pictures')) {
    $form['openid_connect_user_pictures'] = array(
      '#title' => t('Fetch user profile picture from login provider'),
      '#description' => t('Whether the user profile picture from the login provider should be fetched and saved locally.'),
      '#type' => 'checkbox',
      '#default_value' => variable_get('openid_connect_user_pictures', TRUE),
    );
  }
  $form['userinfo_mapping'] = array(
    '#title' => t('User claims mapping'),
    '#type' => 'fieldset',
  );
  $user_entity_wrapper = entity_metadata_wrapper('user');
  $claims = openid_connect_claims_options();
  $properties = $user_entity_wrapper
    ->getPropertyInfo();
  $properties_skip = _openid_connect_user_properties_to_skip();
  foreach ($properties as $property_name => $property) {
    if (isset($properties_skip[$property_name])) {
      continue;
    }

    // Always map the timezone.
    $default_value = 0;
    if ($property_name == 'timezone') {
      $default_value = 'zoneinfo';
    }
    $form['userinfo_mapping']['openid_connect_userinfo_mapping_property_' . $property_name] = array(
      '#type' => 'select',
      '#title' => $property['label'],
      '#description' => $property['description'],
      '#options' => $claims,
      '#empty_value' => 0,
      '#empty_option' => t('- No mapping -'),
      '#default_value' => variable_get('openid_connect_userinfo_mapping_property_' . $property_name, $default_value),
    );
  }
  $form['actions']['#type'] = 'actions';
  $form['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save configuration'),
  );
  return $form;
}