You are here

function domain_roles_form in Domain Access 7.3

Same name and namespace in other branches
  1. 6.2 domain.admin.inc \domain_roles_form()
  2. 7.2 domain.admin.inc \domain_roles_form()

FormsAPI to set default domain membership for each role.

These settings are added to the $user object.

See also

domain_get_user_domains()

1 string reference to 'domain_roles_form'
domain_menu in ./domain.module
Implements hook_menu().

File

./domain.admin.inc, line 1089
Administration functions for the domain module.

Code

function domain_roles_form($form, &$form_state) {
  $form = array();
  $form['domain_add_roles'] = array(
    '#type' => 'radios',
    '#options' => array(
      0 => t('Add default roles dynamically'),
      1 => t('Add default roles to the user account'),
    ),
    '#title' => t('Role settings behavior'),
    '#description' => t('Adding role settings to the user account will permanently save them for each user on account updates. Otherwise, role-based settings can be added or removed at will.'),
    '#default_value' => variable_get('domain_add_roles', 0),
  );
  $roles = user_roles();
  $defaults = variable_get('domain_roles', array());
  $roles[0] = t('new user');
  ksort($roles);
  $form['domain_roles'] = array(
    '#tree' => TRUE,
    '#value' => '<p>' . t('You may set optional default domains for each site user role. These settings will be added to each user when determining the permissions the user has to view and edit content on your site. These settings are expressly needed if you allow <em>anonymous users</em> to post content on your site.') . '</p>',
  );
  $domains = array();
  foreach (domain_domains() as $key => $value) {
    $domains[$value['machine_name']] = $value['sitename'];
  }
  foreach ($roles as $rid => $role) {
    $form['domain_roles'][$rid]['#tree'] = TRUE;
    $title = t('All domains');
    $form['#domain_roles'][DOMAIN_ALL] = $title;
    $form['domain_roles'][$rid][DOMAIN_ALL] = array(
      '#title' => $title,
      '#type' => 'checkbox',
      '#default_value' => isset($defaults[$rid][DOMAIN_ALL]) ? $defaults[$rid][DOMAIN_ALL] : 0,
    );
    foreach ($domains as $machine_name => $domain) {
      $form['#domain_roles'][$machine_name] = $domain;
      $form['domain_roles'][$rid][$machine_name] = array(
        '#title' => filter_xss_admin($domain),
        '#type' => 'checkbox',
        '#default_value' => isset($defaults[$rid][$machine_name]) ? $defaults[$rid][$machine_name] : 0,
        '#states' => array(
          'disabled' => array(
            'input[name="domain_roles[' . $rid . '][' . DOMAIN_ALL . ']"]' => array(
              'checked' => TRUE,
            ),
          ),
        ),
      );
    }
  }
  $form = system_settings_form($form);

  // System settings form adds a theme we cannot use.
  unset($form['#theme']);
  return $form;
}