You are here

function hosting_client_form_user_profile_form_alter in Hosting 7.4

Same name and namespace in other branches
  1. 7.3 client/hosting_client.access.inc \hosting_client_form_user_profile_form_alter()

Implements hook_form_FORM_ID_alter().

Add items to the user forms when editing or registering.

See also

hosting_client_user()

File

client/hosting_client.access.inc, line 87
Control client node access.

Code

function hosting_client_form_user_profile_form_alter(&$form, &$form_state, $form_id) {
  if ($form['#user_category'] == 'account') {
    $user = $form['#user'];

    // In Aegir 3.x the admin account does not have the client_id array and sometimes a normal user
    // is missing it, as well.  If it isn't on the user object, add it.
    if (!is_array($user->client_id)) {
      $user->client_id = hosting_get_client_from_user($user->uid);
    }
    $clients = array();
    if ($user->client_id) {
      foreach ($user->client_id as $client => $type) {
        $clients[$client] = '';
        $form['client_edit']['name'][$client] = array(
          '#type' => 'markup',
          '#value' => _hosting_node_link($client),
        );
      }
    }
    if (user_access('edit client users')) {
      $form['client_edit']['clients'] = array(
        '#type' => 'checkboxes',
        '#options' => $clients,
      );
    }
    $form['client_edit']['header'] = array(
      '#type' => 'value',
      '#value' => array(
        array(
          'data' => t('Accessible clients'),
        ),
        array(
          'data' => t('Remove'),
        ),
      ),
    );
    if (user_access('edit client users')) {
      $form['client_edit']['hosting_client'] = array(
        '#type' => 'textfield',
        '#title' => t('Associate a client to this user'),
        '#weight' => 2,
        '#autocomplete_path' => 'hosting_client/autocomplete/client',
        '#description' => t('This field allows you to associate an existing client to a user.
                             It does not create a new client, but allows this user
                             to manage sites belonging to the given client.'),
      );
    }
    $form['client_edit']['#theme'] = 'hosting_client_user_form';
    $form['#validate'][] = 'hosting_client_user_form_validate';
  }
}