function domain_form_user_form_alter in Domain Access 7.3
Same name and namespace in other branches
- 8 domain/domain.module \domain_form_user_form_alter()
- 7.2 domain.module \domain_form_user_form_alter()
Helper function for the two user forms we care about.
2 calls to domain_form_user_form_alter()
- domain_form_user_profile_form_alter in ./
domain.module - Implements hook_form_FORM_ID_alter().
- domain_form_user_register_form_alter in ./
domain.module - Implements hook_form_FORM_ID_alter().
File
- ./
domain.module, line 678 - Core module functions for the Domain Access suite.
Code
function domain_form_user_form_alter(&$form, &$form_state) {
// Only act on our forms.
if (is_null($form['#user_category']) || !in_array($form['#user_category'], array(
'account',
'register',
))) {
return;
}
$_domain = domain_get_domain();
// Get the domains for this user, but ignore roles unless told to use them.
$add_roles = variable_get('domain_add_roles', 0);
// In the register case, we take the 'new user' settings.
if ($form['#user_category'] == 'register') {
$add_roles = TRUE;
}
$account = $form['#user'];
$account->domain_user = domain_get_user_domains($account, $add_roles);
// By default, the requesting domain is assigned on registration.
if (empty($account->uid)) {
$default = array(
$_domain['domain_id'] => $_domain['domain_id'],
);
}
else {
$default = $account->domain_user;
}
if (user_access('assign domain editors')) {
// Set the form options.
$domains = domain_domains();
$options = array();
foreach ($domains as $domain) {
$options[$domain['domain_id']] = check_plain($domain['sitename']);
}
$format = domain_select_format();
$form['domain'] = array(
'#type' => 'fieldset',
'#title' => t('Domain access'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
$form['domain']['domain_user'] = array(
'#type' => empty($format) ? 'checkboxes' : 'select',
'#options' => $options,
'#title' => t('Domain access settings'),
'#description' => t('Select the affiliates that this user belongs to. Used to grant editing permissions for users with the "edit domain content" permission.'),
'#default_value' => $default,
);
if ($format) {
$form['domain']['domain_user']['#multiple'] = TRUE;
$form['domain']['domain_user']['#size'] = count($options) > 10 ? 10 : count($options);
}
}
else {
$form['domain'] = array(
'domain_user' => array(
'#type' => 'value',
'#value' => $default,
),
);
}
}