domain_roles_form

Versions
domain
domain_roles_form($form_state)

FormsAPI to set default domain membership for each role.

These settigns are added to the $user object.

See also

domain_get_user_domains()

Code

./domain.admin.inc, line 1055

<?php
function domain_roles_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) {
    if ($key > 0) {
      $domains[$key] = $value['sitename'];
    }
    else {
      $domains[-1] = $value['sitename'];
    }
  }
  foreach ($roles as $rid => $role) {
    $form['domain_roles'][$rid]['#tree'] = TRUE;
    foreach ($domains as $domain_id => $domain) {
      $form['domain_roles'][$rid][$domain_id] = array(
        '#title' => filter_xss_admin($domain),
        '#type' => 'checkbox',
        '#default_value' => (isset($defaults[$rid][$domain_id])) ? $defaults[$rid][$domain_id] : 0,
      );
    }
  }

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

Contact

  • agentrickard [at] gmail [dot] com

Donations

My Amazon.com Wish List