function hosting_server_form in Hosting 6.2
Same name and namespace in other branches
- 7.4 server/hosting_server.module \hosting_server_form()
- 7.3 server/hosting_server.module \hosting_server_form()
Implementation of hook_form().
File
- server/
hosting_server.module, line 211
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['services'] = array(
'#weight' => -5,
'#tree' => TRUE,
);
if (!$node->nid) {
$node->services = array();
$node->ip_addresses = array();
}
// taken mostly from the hosting_site alias stuff
$form['ips_wrapper'] = array(
'#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>'),
'#type' => 'fieldset',
'#tree' => FALSE,
'#weight' => -9,
'#prefix' => '<div class="clear-block" id="hosting-ips-wrapper">',
'#suffix' => '</div>',
);
$form['ips_wrapper']['ip_addresses'] = array(
'#prefix' => '<div id="hosting-ip-addresses">',
'#suffix' => '</div>',
'#tree' => TRUE,
);
// Get the list of existing IPs
$ips = $node->ip_addresses;
$ips_count = max(3, empty($ips) ? 3 : count($ips) + 1);
// Add alias textfields
foreach ($ips as $id => $ip) {
$form['ips_wrapper']['ip_addresses'][$id] = array(
'#type' => 'textfield',
'#default_value' => $ip,
);
$ips_count--;
}
$form['ips_wrapper']['new_ip_addresses'] = array(
'#prefix' => '<div id="hosting-ip-addresses">',
'#suffix' => '</div>',
'#tree' => TRUE,
);
for ($delta = 0; $delta < $ips_count; $delta++) {
$form['ips_wrapper']['new_ip_addresses'][$delta] = array(
'#type' => 'textfield',
);
}
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;
}