You are here

function domain_path_node_validate in Domain Path 7

Implements hook_node_validate().

File

./domain_path.module, line 349
Path alias handling for multiple domains.

Code

function domain_path_node_validate($node, $form, &$form_state) {

  // No validatio on node delete, alias delete, or alias override.
  $op = $form_state['values']['op'];
  $delete = $form_state['values']['domain_path']['domain_path_delete'];
  if (!empty($delete) || $op == t('Delete')) {
    return;
  }
  $paths = $form_state['values']['domain_path'];
  unset($paths['domain_path_delete']);
  $alias = $form_state['values']['path']['alias'];

  // Make sure we don't duplicate anything.
  foreach ($paths as $domain_id => $path) {
    $key = $domain_id == -1 ? 0 : $domain_id;
    if (!empty($path) && $path == $alias) {
      form_set_error("domain_path][{$key}", t('Domain path %alias may not match the default path alias. You may leave the element blank.', array(
        '%alias' => $path,
      )));
      $set_message = TRUE;
    }
    elseif (!empty($path)) {
      $query = db_query("SELECT COUNT(dpid) FROM {domain_path}\n        WHERE domain_id = :domain_id\n        AND alias = :alias\n        AND language = :language\n        AND source != :source", array(
        ':domain_id' => $key,
        ':alias' => $path,
        ':language' => isset($node->language) ? $node->language : LANGUAGE_NONE,
        ':source' => "node/{$node->nid}",
      ));
      if ($query
        ->fetchField() > 0) {
        $domain = domain_lookup($domain_id);
        form_set_error("domain_path][{$key}", t('Domain path %alias matches an existing domain path alias for %domain.', array(
          '%alias' => $path,
          '%domain' => $domain['path'],
        )));
      }
    }
  }
}