You are here

function cas_roles_admin_settings in CAS roles 6

Same name and namespace in other branches
  1. 8 cas_roles.admin.inc \cas_roles_admin_settings()
  2. 7.2 cas_roles.admin.inc \cas_roles_admin_settings()
  3. 7 cas_roles.admin.inc \cas_roles_admin_settings()

Administrative settings form.

1 string reference to 'cas_roles_admin_settings'
cas_roles_menu in ./cas_roles.module
Implements hook_menu().

File

./cas_roles.admin.inc, line 11
Provides settings pages for the CAS Attributes module.

Code

function cas_roles_admin_settings() {

  // Get current settings, and add default options.
  $sync_every_login = variable_get('cas_roles_sync_every_login', 0);
  $behavior = variable_get('cas_roles_behavior', CAS_ROLES_DRUPAL_ROLES_ONLY);
  $roles = variable_get('cas_roles_roles', '');
  $relations = variable_get('cas_roles_relations', array(
    '2' => '',
  ));
  $form['cas_roles_sync_every_login'] = array(
    '#type' => 'radios',
    '#title' => t('Fetch CAS Roles'),
    '#default_value' => $sync_every_login,
    '#options' => array(
      0 => t('only when a CAS account is created (i.e., the first login of a CAS user).'),
      1 => t('every time a CAS user logs in.'),
    ),
    '#weight' => -10,
  );
  $form['cas_roles_behavior'] = array(
    '#type' => 'radios',
    '#title' => t('CAS vs Drupal roles'),
    '#default_value' => $behavior,
    '#options' => array(
      CAS_ROLES_DRUPAL_ROLES_ONLY => t("Only assign roles which are present in drupal and match, remove user roles not present in CAS."),
      CAS_ROLES_CREATE_NEW_ROLES => t("Create roles which don't exits in Drupal, remove user roles not present in CAS."),
      CAS_ROLES_MATCH_REGEX => t("Match roles with regular expressions."),
    ),
    '#weight' => -9,
  );
  $form['cas_roles_roles'] = array(
    '#type' => 'textfield',
    '#title' => t('Attribute for roles'),
    '#default_value' => isset($roles) ? $roles : '',
    '#size' => 50,
    '#description' => t('Attributes may be arrays, use the format of tokens. Example: [cas-attribute-drupal_roles]'),
  );
  $form['cas_roles_relations'] = array(
    // TODO: make this responsive imediately, like in D7
    // If we hide it instead of collapsing it, the mpping is lost if another behavior is selected
    '#type' => 'fieldset',
    '#collapsible' => $behavior == CAS_ROLES_MATCH_REGEX ? FALSE : TRUE,
    '#collapsed' => $behavior == CAS_ROLES_MATCH_REGEX ? FALSE : TRUE,
    '#title' => t('CAS roles mappings'),
    'relations' => array(),
    '#tree' => TRUE,
  );
  if ($behavior == CAS_ROLES_MATCH_REGEX) {

    // There seems to be a problem with this help text in a collapsible fieldset.
    $form['cas_roles_relations']['help'] = array(
      '#value' => t('Regular expression to map <a href="@url">user roles</a>. The role is assigned if one of the roles in the attribute array matches the expression. An empty field means the role is not administrated by CAS.', array(
        '@url' => url('admin/user/roles'),
      )),
    );
  }
  foreach (cas_roles_cutsom_user_roles() as $rid => $role) {
    $form['cas_roles_relations'][$rid] = array(
      '#type' => 'textfield',
      '#title' => t($role),
      '#default_value' => isset($relations[$rid]) ? $relations[$rid] : '',
      '#size' => 50,
      '#maxlength' => 1024,
      '#element_validate' => array(
        '_cas_roles_preg_validate',
      ),
    );
  }
  $form['token_tree'] = array(
    '#value' => theme('token_tree', array(
      'cas',
    ), FALSE),
  );
  return system_settings_form($form);
}