You are here

function hosting_alias_validate_alias in Hosting 7.4

Same name and namespace in other branches
  1. 6.2 alias/hosting_alias.module \hosting_alias_validate_alias()
  2. 7.3 alias/hosting_alias.module \hosting_alias_validate_alias()

Ensure that an alias is valid, and not already in use.

Parameters

object $site: A Hosting site node.

string $alias: An alias to have point to the site.

string $key: The array index of this alias, to set any error on the proper sub-field.

2 calls to hosting_alias_validate_alias()
hosting_alias_site_form_validate in alias/hosting_alias.module
Validation handler for site form.
hosting_subdirs_validate_alias in subdirs/hosting_subdirs.module
Ensure that an alias is valid for subdir site.

File

alias/hosting_alias.module, line 397
Allow sites to have domain aliases that they can be accessed with.

Code

function hosting_alias_validate_alias($site, $alias, $key) {
  $alias = hosting_site_clean_domain($alias);
  $params = isset($site->nid) ? array(
    'nid' => $site->nid,
  ) : array();
  $length = strlen($alias);
  if (!hosting_domain_allowed($alias, $params) || $alias == $site->title) {
    form_set_error("aliases][{$key}", t('The domain name @alias is already in use', array(
      '@alias' => $alias,
    )));
  }
  if (!_hosting_valid_fqdn_wildcard($alias)) {
    form_set_error("aliases][{$key}", t('The domain name @alias is not a valid url', array(
      '@alias' => $alias,
    )));
  }
  if ($length > HOSTING_MAX_ALIAS_LENGTH) {
    $long = $length - HOSTING_MAX_ALIAS_LENGTH;
    form_set_error("aliases][{$key}", t('The domain name @alias is @long character(s) too long. Please shorten.', array(
      '@alias' => $alias,
      '@long' => $long,
    )));
  }
}