forum_validate

Definition

forum_validate($node)
modules/forum.module, line 356

Description

Implementation of hook_validate().

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

Code

<?php
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))));
        }
      }
    }
  }
}
?>
 
 

Drupal is a registered trademark of Dries Buytaert.