You are here

function _hosting_client_site_default in Hostmaster (Aegir) 6

Get the default value of the client field for a site node.

Parameters

$node: The site to the the clients for.

1 call to _hosting_client_site_default()
hosting_site_form in modules/hosting/site/hosting_site.form.inc
Implements hook_form().

File

modules/hosting/client/hosting_client.module, line 622

Code

function _hosting_client_site_default($node) {

  # find the right client
  global $user;
  $current_client_id = 0;
  if ($user->uid) {
    $client_ids = hosting_get_client_from_user($user->uid);
    $clients = array();
    foreach ($client_ids as $client_id => $client_permissions) {
      $client_id = $client_id ? $client_id : HOSTING_DEFAULT_CLIENT;
      $client = node_load($client_id);
      $clients[$client->title] = $client->title;
      if ($node->client == $client_id || !$current_client_id) {
        $current_client_id = $client_id;
      }
    }
    if (!$current_client_id && !user_access('administer clients')) {
      form_set_error('client', t('Your user is not associated with any clients so you are not allowed to create new sites'));
    }
  }
  if (!$current_client_id) {
    $current_client_id = HOSTING_DEFAULT_CLIENT;
  }

  // allow admins to override
  if ($node->client && user_access('administer clients')) {
    $current_client_id = $node->client;
  }
  $client = node_load($current_client_id);
  if (!$client) {

    # we give up, couldn't find a client, we're probably in a preview so

    # just use the node client
    $client = new stdClass();
    $client->title = $node->client;
  }
  return $client->title;
}