function hosting_site_validate in Hostmaster (Aegir) 6
Implements hook_validate().
File
- modules/
hosting/ site/ hosting_site.form.inc, line 277 - Site node form.
Code
function hosting_site_validate($node, &$form) {
global $user;
$valid_options = hosting_site_available_options($node);
$url = strtolower(trim($node->title));
// domain names are case-insensitive
if (!_hosting_valid_fqdn($url)) {
form_set_error('title', t("You have not specified a valid url for this site."));
}
if (!$node->new_client) {
$client = hosting_get_client($node->client);
if (!$node->client || !$client) {
form_set_error('client', t('Please fill in a valid client'));
}
if (!user_access('administer clients') && !array_key_exists($client->nid, hosting_get_client_from_user($user->uid))) {
form_set_error('client', t('Access denied to client @client', array(
'@client' => $client->title,
)));
}
$node->client = $client->nid;
}
// TODO: maybe we should allow creation of sites that conflict with HOSTING_SITE_DISABLED (which would then need to be renamed before being re-enabled)
if (!hosting_domain_allowed($url, (array) $node)) {
form_set_error('title', t("The domain name you have specified is already in use."));
}
// If the quota module is loaded and this is a new node, check
// the site quota
if (!$node->nid && function_exists('hosting_site_quota_exceeded')) {
$quota_error = hosting_site_quota_exceeded((array) $node);
if ($quota_error) {
form_set_error('title', $quota_error);
}
}
if (!in_array($node->profile, $valid_options['profile']) && !$node->nid) {
form_set_error('profile', t('Please choose a valid profile'));
}
if (!in_array($node->platform, $valid_options['platform']) && !$node->nid) {
form_set_error('platform', t('Please choose a valid platform'));
}
// Check that we are selecting a valid language for this profile, but only when a new site is created.
if (!in_array($node->site_language, $valid_options['site_language']) && !$node->nid) {
form_set_error('site_language', t('Please fill in a valid language'));
}
}