forum_node_validate

Versions
mediamosa-21
forum_node_validate($node, $form)

Implements hook_node_validate().

Check in particular that only a "leaf" term in the associated taxonomy.

Code

modules/forum/forum.module, line 264

<?php
function forum_node_validate($node, $form) {
  if (_forum_node_check_node_type($node)) {
    $langcode = $form['taxonomy_forums']['#language'];
    // vocabulary is selected, not a "container" term.
    if (!empty($node->taxonomy_forums[$langcode])) {
      // Extract the node's proper topic ID.
      $containers = variable_get('forum_containers', array());
      foreach ($node->taxonomy_forums[$langcode] as $item) {
        $term = taxonomy_term_load($item['tid']);
        $used = db_query_range('SELECT 1 FROM {taxonomy_term_data} WHERE tid = :tid AND vid = :vid',0 , 1, array(
          ':tid' => $term->tid,
          ':vid' => $term->vid,
        ))->fetchField();
        if ($used && in_array($term->tid, $containers)) {
          form_set_error('taxonomy_forums', t('The item %forum is a forum container, not a forum. Select one of the forums below instead.', array('%forum' => $term->name)));
        }
      }
    }
  }
}
?>