--- /dev/null 2005-11-20 21:22:37.000000000 -0600 +++ compat/category_compat_forum.info 2007-02-08 10:32:23.000000000 -0600 @@ -0,0 +1,5 @@ +; $Id$ +name = Category compatibility: Forum +description = Compatibility routines to improve compatibility with the Forum module. +package = Category +dependencies = category forum --- /dev/null 2005-11-20 21:22:37.000000000 -0600 +++ compat/category_compat_forum.module 2007-02-08 11:34:17.000000000 -0600 @@ -0,0 +1,62 @@ +type == 'forum') { + switch ($op) { + case 'validate': + if ($node->category) { + // Since forum can't directly file errors anymore, it's our job. + $container = variable_get('forum_nav_vocabulary', ''); + $cats = variable_get('forum_containers', array()); // Ironically, forum compensates for taxonomy's limitations. + foreach ($node->category as $cat) { + $cat = category_get_category($cat); + if ($cat->cnid == $container) { + if (in_array($cat->cid, $cats)) { + form_set_error('category', t('The item %forum is only a container for forums. Please select one of the forums below it.', array('%forum' => $cat->title))); + } + } + } + } + break; + case 'prepare': + if (!$node->nid) { + // New topic. Attempt to grab our cid. + if (is_numeric(arg(3))) { + // These will be picked up during render. + $node->category[arg(3)]->cnid = _forum_get_vid(); + $node->category[arg(3)]->cid = arg(3); + } + } + break; + } + } +} + +/** + * Implementation of hook_link_alter(). + * Links to forum categories need to point to forum/ + * to ensure proper display. + */ +function category_compat_forum_link_alter(&$node, &$links) { + if ($node->type == 'forum') { + foreach ($links as $module => $link) { + if (strpos($module, 'category_cat_')===0) { + // Link back to the forum page. + $cat = str_replace('node/', '', $link['href']); + $cat = category_get_category($cat); + if ($cat->cnid == _forum_get_vid()) { + $links[$module]['href'] = str_replace('node', 'forum', $link['href']); + } + } + } + } +}