You are here

function hosting_site_form in Hosting 5

Same name and namespace in other branches
  1. 6.2 site/hosting_site.form.inc \hosting_site_form()
  2. 7.4 site/hosting_site.form.inc \hosting_site_form()
  3. 7.3 site/hosting_site.form.inc \hosting_site_form()

Implementation of hook_form

TODO: additional nested logic. Certain profiles are available only on certain platforms, and certain languages on certain profiles.

1 call to hosting_site_form()
_hosting_signup_form in signup/hosting_signup.module
Remote form definition

File

site/hosting_site.module, line 196

Code

function hosting_site_form($node) {
  drupal_add_js(drupal_get_path('module', 'hosting_site') . '/hosting_site_form.js');
  drupal_add_css(drupal_get_path('module', 'hosting_site') . '/hosting_site_form.css');
  $type = node_get_types('type', $node);
  if ($node->nid) {
    $form['info']['#prefix'] = '<div class="clear-block" id="hosting-site-edit-info">';
    $form['info']['#suffix'] = '<br /></div>';
  }

  // We need to define form elements for the node's title and body.
  if (!$node->nid) {
    $form['title'] = array(
      '#type' => 'textfield',
      '#title' => t('Domain name'),
      '#required' => TRUE,
      '#default_value' => $node->title,
      '#weight' => -5,
    );
  }
  else {
    $form['info']['title'] = array(
      '#type' => 'item',
      '#title' => t('Domain name'),
      '#value' => $node->title,
      '#weight' => -5,
    );
    $form['title'] = array(
      '#type' => 'hidden',
      '#value' => $node->title,
    );
  }

  # find the right client
  global $user;
  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;
      }
    }
  }
  else {
    $current_client_id = HOSTING_DEFAULT_CLIENT;
  }

  // allow admins to override
  if ($node->client && user_access('administer site')) {
    $current_client_id = $node->client;
  }
  $client = node_load($current_client_id);
  if ((!$node->client || $node->nid) && user_access('administer site')) {
    $form['client'] = array(
      '#type' => 'textfield',
      '#required' => TRUE,
      '#title' => t('Client'),
      '#default_value' => $client->title,
      '#description' => t('The client who this site belongs to.'),
      '#autocomplete_path' => 'hosting_client/autocomplete/client',
    );
  }
  elseif ($node->client) {
    $form['client'] = array(
      '#type' => 'hidden',
      '#value' => $client->title,
    );
    $form['info']['client'] = array(
      '#type' => 'item',
      '#title' => t('Client'),
      '#value' => $client->title,
    );
  }
  else {
    $form['client'] = array(
      '#type' => 'radios',
      '#title' => t('Client'),
      '#default_value' => key($clients),
      '#options' => $clients,
      '#description' => t('The client who this site belongs to.'),
    );
  }
  if (!$node->nid) {
    $platforms = _hosting_get_platforms();
    if (sizeof($platforms) > 1) {
      $form['platform'] = array(
        '#type' => 'radios',
        '#title' => t('Platform'),
        '#required' => TRUE,
        '#description' => t('The platform you want the site to be hosted on.'),
        '#options' => $platforms,
        '#default_value' => HOSTING_DEFAULT_PLATFORM,
      );
    }
    else {
      $form['platform'] = array(
        '#type' => 'hidden',
        '#value' => key($platforms),
      );
    }
    $form['profile'] = _hosting_site_form_profile();
    $form['language'] = _hosting_site_form_language();
  }
  else {
    $form['info']['platform'] = array(
      '#type' => 'item',
      '#title' => t('Platform'),
      '#value' => _hosting_node_link($node->platform),
    );
    $form['platform'] = array(
      '#type' => 'hidden',
      '#value' => $node->platform,
    );
    $form['info']['profile'] = array(
      '#type' => 'item',
      '#title' => t('Install Profile'),
      '#value' => _hosting_node_link($node->profile),
    );
    $form['profile'] = array(
      '#type' => 'hidden',
      '#value' => $node->profile,
    );
    $form['info']['language'] = array(
      '#type' => 'item',
      '#title' => t('Language'),
      '#value' => _hosting_language_name($node->language),
    );
    $form['language'] = array(
      '#type' => 'hidden',
      '#value' => $node->language,
    );
  }
  if (!$node->nid) {
    $db_servers = _hosting_get_db_servers();
    if (sizeof($db_servers) > 1) {
      $form['db_server'] = array(
        '#type' => 'radios',
        '#title' => t('Database server'),
        '#required' => TRUE,
        '#description' => t('The database server the site will use to host it\'s content.'),
        '#options' => $db_servers,
        '#default_value' => $node->db_server,
      );
    }
    else {
      $form['db_server'] = array(
        '#type' => 'hidden',
        '#value' => key($db_servers),
      );
    }
  }
  else {
    $form['info']['db_server'] = array(
      '#type' => 'item',
      '#title' => t('Database Server'),
      '#value' => _hosting_node_link($node->db_server),
    );
    $form['db_server'] = array(
      '#type' => 'hidden',
      '#value' => $node->db_server,
    );
  }
  return $form;
}