You are here

function hosting_server_form in Hostmaster (Aegir) 6

Implementation of hook_form().

File

modules/hosting/server/hosting_server.module, line 207

Code

function hosting_server_form(&$node) {
  drupal_add_js(drupal_get_path('module', 'hosting_server') . '/hosting_server.js');
  $form['title'] = array(
    '#type' => 'textfield',
    '#title' => t('Server hostname'),
    '#required' => TRUE,
    '#default_value' => $node->title,
    '#description' => t('The host name of the server. This is the address that will be used by Hostmaster to connect to the server to issue commands. It is to resolve to the internal network, if you have such a separation.<br /><strong>Be careful when changing the node title, it is used to create the SQL users if the IP address, below, is not set.</strong>'),
    '#weight' => -10,
  );
  $form['ip_addresses'] = array(
    '#type' => 'textarea',
    '#title' => t('Ip addresses'),
    '#description' => t('A list of IP addresses this server is publicly available under, one per line. If none is specified, a DNS lookup will be performed based on the server hostname above. <br /><strong>This should point to the public network, if you have such a separation.</strong>'),
    '#default_value' => implode("\n", _hosting_ip_list($node->ip_addresses)),
    '#weight' => -9,
  );
  $form['services'] = array(
    '#weight' => -5,
    '#tree' => TRUE,
  );
  if (!$node->nid) {
    $node->services = array();
  }
  foreach (hosting_server_services() as $name => $service) {
    $form['services'][$name] = array(
      '#type' => 'fieldset',
      '#title' => $service['title'],
      '#prefix' => '<div class="hosting-service-form">',
      '#suffix' => '</div>',
      '#weight' => isset($service['weight']) ? $service['weight'] : 0,
    );
    $form['services'][$name]['type'] = array(
      '#type' => 'radios',
      '#weight' => -99,
      '#options' => array_merge(array(
        'null' => 'None',
      ), drupal_map_assoc(array_keys($service['types']))),
      '#default_value' => isset($node->services[$name]->available) && $node->services[$name]->available ? $node->services[$name]->type : 'null',
    );

    // Service-specific configuration.
    foreach ($service['types'] as $type => $class) {
      $form['services'][$name][$type] = array(
        '#prefix' => '<div id="provision-service-settings-' . $name . '-' . $type . '" class="provision-service-settings-' . $name . '">',
        '#suffix' => '</div>',
      );
      if (isset($node->services[$name]) && $node->services[$name]->type === $type) {
        $node->services[$name]
          ->form($form['services'][$name][$type]);
      }
      else {
        $service_object = hosting_services_new_object($name, $type, $node);
        $service_object
          ->form($form['services'][$name][$type]);
      }
    }
  }
  return $form;
}