function hosting_alias_validate_alias

7.x-3.x hosting_alias.module hosting_alias_validate_alias($site, $alias, $key)

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 361
Allow sites to have domain aliases that they can be accessed with.

Code

function hosting_alias_validate_alias($site, $alias, $key) {
  if ($alias = trim($alias)) {
    $params = isset($site->nid) ? array('nid' => $site->nid) : array();
    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)));
    }
    $length = strlen($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)));
    }

  }
}