You are here

function domain_form_user_form_alter in Domain Access 7.2

Same name and namespace in other branches
  1. 8 domain/domain.module \domain_form_user_form_alter()
  2. 7.3 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 496
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, TRUE);

  // By default, the requesting domain is assigned on registration.
  if (empty($account->uid)) {
    $_domain['domain_id'] == 0 ? $default = array(
      -1,
    ) : ($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) {

      // Handle 0 and -1
      if ($domain['domain_id'] == variable_get('default_domain', 0)) {
        $domain['domain_id'] = -1;
      }
      $options[$domain['domain_id']] = check_plain($domain['sitename']);
    }
    $format = domain_select_format();
    $form['domain_user'] = array(
      '#type' => 'fieldset',
      '#title' => t('Domain access'),
      '#collapsible' => TRUE,
      '#collapsed' => FALSE,
      '#weight' => 1,
    );
    $form['domain_user']['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_user']['domain_user']['#multiple'] = TRUE;
      $form['domain_user']['domain_user']['#size'] = count($options) > 10 ? 10 : count($options);
    }
  }
  else {
    $form['domain_user'] = array(
      '#type' => 'value',
      '#value' => $default,
    );
  }
}