forum_node_validate

Versions
7
forum_node_validate($node, $form)

Implement hook_node_validate().

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

Code

modules/forum/forum.module, line 203

<?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 only a forum container. Select one of the forums below it.', array('%forum' => $term->name)));
        }
      }
    }
  }
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.