You are here

function domain_form_user_admin_account_alter in Domain Access 6.2

Same name and namespace in other branches
  1. 7.3 domain.module \domain_form_user_admin_account_alter()
  2. 7.2 domain.module \domain_form_user_admin_account_alter()

Implement hook_form_alter().

File

./domain.module, line 610
Core module functions for the Domain Access suite.

Code

function domain_form_user_admin_account_alter(&$form, $form_state) {
  global $_domain;
  if (!user_access('assign domain editors')) {
    return;
  }
  $options = array();
  $format = domain_select_format();
  foreach (domain_domains() as $data) {

    // Cannot pass zero in checkboxes.
    $data['domain_id'] == 0 ? $key = -1 : ($key = $data['domain_id']);

    // The domain must be valid.
    if ($data['valid'] || user_access('access inactive domains')) {

      // Filter checkbox output but not select list.
      $options[$key] = empty($format) ? check_plain($data['sitename']) : $data['sitename'];
    }
  }
  $form['domain'] = array(
    '#type' => 'fieldset',
    '#title' => t('Affiliate editor options'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#prefix' => '<div class="description">' . t('If you select <em>Assign users to domains</em> above, you should confirm the <em>Affiliate editor options</em> settings below.') . '</div>',
    '#weight' => -1,
  );
  $form['domain']['behavior'] = array(
    '#type' => 'radios',
    '#title' => t('Update behavior'),
    '#options' => array(
      0 => t('Replace old values with new settings'),
      1 => t('Add new settings to existing values'),
      2 => t('Remove selected domains from existing values'),
    ),
    '#description' => t('Defines how new grants will be applied to the updated users.'),
    '#default_value' => 0,
  );
  $form['domain']['domains'] = array(
    '#type' => empty($format) ? 'checkboxes' : 'select',
    '#title' => t('Assign to'),
    '#options' => $options,
    '#required' => FALSE,
    '#description' => t('Select which affiliates these users should belong to. <em>Note: this will erase any current assignment for the selsected users.</em>'),
    '#default_value' => array(
      $_domain['domain_id'] == 0 ? -1 : $_domain['domain_id'],
    ),
  );
  if ($format) {
    $form['domain']['domains']['#multiple'] = TRUE;
    $form['domain']['domains']['#size'] = count($options) > 10 ? 10 : count($options);
  }

  // Add our domain elements. $form['name'] should be an array of matching users.
  if (!empty($form['name'])) {
    foreach (array_keys($form['name']) as $uid) {
      $form['user_domains'][$uid][0] = array(
        '#value' => theme('item_list', _domain_user_list($uid)),
      );
    }
  }
  $form['#theme'] = 'domain_admin_users_form';
  $form['#submit'][] = 'domain_update_users';
}