You are here

function domain_batch_validate in Domain Access 7.2

Same name and namespace in other branches
  1. 5 domain.module \domain_batch_validate()
  2. 6.2 domain.module \domain_batch_validate()

Validate handler for hook_domainbatch()

1 string reference to 'domain_batch_validate'
domain_domainbatch in ./domain.module
Implements hook_domainbatch()

File

./domain.module, line 2693
Core module functions for the Domain Access suite.

Code

function domain_batch_validate($values) {
  $case = $values['variable'];
  $batch = $values['domain_batch'];
  switch ($case) {
    case 'domain_root':
      $errors = array();
      foreach ($batch as $key => $value) {
        $subdomain = strtolower(urlencode($value));
        $check = db_query("SELECT COUNT(domain_id) FROM {domain} WHERE subdomain = :subdomain AND domain_id <> :domain_id", array(
          ':subdomain' => $value,
          ':domain_id' => $key,
        ))
          ->fetchField();
        if ($check > 0 || $key > 0 && $value == variable_get('domain_root', '')) {
          form_set_error('domain_batch][' . $key, t('Each domain value must be unique.'));
        }
        else {
          $error = domain_valid_domain($value);
          if (!empty($error)) {
            form_set_error('domain_batch][' . $key, $error);
          }
        }
      }
      break;
    case 'domain_sitename':
      foreach ($batch as $key => $value) {
        $check = db_query("SELECT COUNT(domain_id) FROM {domain} WHERE sitename = :sitename AND domain_id <> :domain_id", array(
          ':sitename' => $value,
          ':domain_id' => $key,
        ))
          ->fetchField();
        if ($check > 0 || $key > 0 && $value == variable_get('domain_sitename', 'Drupal')) {
          form_set_error('domain_batch][' . $key, t('Each site name value must be unique.'));
        }
      }
      break;
  }
}