You are here

function role_expire_admin_settings in Role Expire 7

Configuration form.

1 string reference to 'role_expire_admin_settings'
role_expire_menu in ./role_expire.module
Implements hook_menu().

File

./role_expire.admin.inc, line 11
Administration page.

Code

function role_expire_admin_settings($form, &$form_state) {
  $roles = user_roles();
  $values_raw = variable_get('role_expire_default_roles', '');
  $values = empty($values_raw) ? array() : json_decode($values_raw, TRUE);
  $default = array(
    0 => t('- None -'),
  );

  // It is important to respect the keys on this array merge.
  $roles_select = $default + $roles;

  // Role anonymous.
  unset($roles_select[1]);

  // Role authenticated.
  unset($roles_select[2]);
  $form['general'] = array(
    '#type' => 'fieldset',
    '#title' => t('General settings'),
    '#weight' => 1,
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
  );
  foreach ($roles as $rid => $role_name) {
    if ($rid > 2) {
      $form['general'][$rid] = array(
        '#type' => 'select',
        '#options' => $roles_select,
        '#title' => t('Role to assign after the role "!r" expires', array(
          '!r' => $role_name,
        )),
        '#default_value' => isset($values[$rid]) ? $values[$rid] : 0,
      );
    }
  }
  $form['submit'] = array(
    '#type' => 'submit',
    '#weight' => 2,
    '#value' => t('Save'),
  );
  return $form;
}