Same name and namespace in other branches
  1. 4.6.x modules/forum.module \forum_validate()
  2. 5.x modules/forum/forum.module \forum_validate()

Implementation of hook_validate().

Check in particular that only a "leaf" term in the associated taxonomy vocabulary is selected, not a "container" term.

File

modules/forum.module, line 356
Enable threaded discussions about general topics.

Code

function forum_validate($node) {
  if ($node->taxonomy) {

    // Extract the node's proper topic ID.
    $vocabulary = variable_get('forum_nav_vocabulary', '');
    $containers = variable_get('forum_containers', array());
    foreach ($node->taxonomy as $term) {
      if (db_result(db_query('SELECT COUNT(*) FROM {term_data} WHERE tid = %d AND vid = %d', $term, $vocabulary))) {
        if (in_array($term, $containers)) {
          $term = taxonomy_get_term($term);
          form_set_error('taxonomy', t('The item %forum is only a container for forums. Please select one of the forums below it.', array(
            '%forum' => theme('placeholder', $term->name),
          )));
        }
      }
    }
  }
}