function hosting_server_form in Hosting 7.4
Same name and namespace in other branches
- 6.2 server/hosting_server.module \hosting_server_form()
- 7.3 server/hosting_server.module \hosting_server_form()
Implements hook_form().
File
- server/
hosting_server.module, line 345
Code
function hosting_server_form($node, &$form_state) {
$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' => 0,
);
$form['human_name'] = array(
'#type' => 'textfield',
'#title' => t('Human-readable name'),
'#default_value' => isset($node->human_name) ? $node->human_name : '',
'#description' => t('<strong>Optional, but recommended.</strong> Internally, Aegir refers to servers by their hostname. The value of this field will be used throughout the UI, and allows for more meaningful names. While not enforced by the system, it is highly recommended that the name assigned to a server be unique.'),
'#weight' => 1,
);
$form['services'] = array(
'#weight' => 5,
'#tree' => TRUE,
);
if (!isset($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, X509 certificates will be offered through the SNI mechanism by TLS-enabled webservers. <br /><strong>This should point to the public network, if you have such a separation.</strong>'),
'#type' => 'fieldset',
'#tree' => FALSE,
'#weight' => 2,
'#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);
// Make sure there's at least 3 fields for IPs
if (count($ips) == 0) {
$ips = [
'',
'',
'',
];
}
// Add alias textfields.
foreach ($ips as $id => $ip) {
$form['ips_wrapper']['ip_addresses'][$id] = array(
'#type' => 'textfield',
'#default_value' => $ip,
);
$ips_count--;
}
$form['services_tabs'] = array(
'#type' => 'vertical_tabs',
);
foreach (hosting_server_services() as $name => $service) {
$form['services'][$name] = array(
'#type' => 'fieldset',
'#group' => 'services_tabs',
'#title' => check_plain($service['title']),
'#weight' => isset($service['weight']) ? $service['weight'] : 0,
);
// Check to ensure at least one service provider for each type exists.
if (array_key_exists('types', $service)) {
$options = array(
'null' => t('None'),
);
foreach ($service['types'] as $type => $class_name) {
$service_objects[$name][$type] = hosting_services_new_object($name, $type, $node);
$options[$type] = $service_objects[$name][$type]
->getName();
}
$form['services'][$name]['type'] = array(
'#type' => 'radios',
'#weight' => -99,
'#options' => $options,
'#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(
'#states' => array(
'visible' => array(
":input[name='services[{$name}][type]']" => array(
'value' => $type,
),
),
),
'#type' => 'container',
);
if (isset($node->services[$name]) && $node->services[$name]->type === $type) {
$node->services[$name]
->form($form['services'][$name][$type]);
}
else {
$service_object = $service_objects[$name][$type];
$service_object
->form($form['services'][$name][$type]);
}
}
}
else {
drupal_set_message(t('No implementations available for the :type service. Please visit the !features_link page and enable one.', array(
':type' => $service['title'],
'!features_link' => l(t('Hosting Features'), '/admin/hosting'),
)), 'warning');
}
}
foreach (array(
'verified',
'platform_status',
) as $extra_attribute) {
$form["{$extra_attribute}"] = array(
'#type' => 'value',
'#value' => isset($node->{$extra_attribute}) ? $node->{$extra_attribute} : NULL,
);
}
return $form;
}