I am putting together a forum for Health Disease and Conditions. I created a "container" for each condition.

The problem is, that on the forum page, right under the container, it says "post new forum topic." This is a bit confusing because to the casual user, that link implies you can post a sub topic to the Container -- especially because the the Forum dropdown menu on the form defaults to the Container Name (e.g., Diabetes), but if you try to do so, an error appears that says you can't post a topic to a container.

So for example:

1) Container = Diabetes
- Post a New Forum Topic (this link appears on the template)

a) Forum 1= Newly Diagnose
b) Forum 2= Recipes
c) etc.

I then try a different approach, which is to use *no* containers as follows:

2) Forum = Diabetes
- Post a New Forum Topic (this link appears on the template)

a) Forum Topic 1 = Newly Diagnosed
b) Forum Topic 2 = Recipes

Approach number 2 seems to work better from a front-end usability perspective, but I want to make sure I'm not missing something before I build out the entire taxonomy of Forum and Topics.

QUESTIONS:
1) What do I lose by not starting with a container?

2) If I do use solution one in the above example (with Containers), how do I remove the initial "Post a Forum Topic" link on the main container page? If I do that, then Users would go into a forum topic first, and then get the Post a New Forum Topic, and the forum will default to Diabetes, and they can also select sub-topics such as Recipes.

Comments

tvs_guy’s picture

Looking for a way to do the same thing.
Also, how to make one Forum allow replies, but not start a new thread, yet allow other forums to have this ability. Still researching. Will post back here if I find the answer(s).

-=thevisualsense.com=-

tvs_guy’s picture

Has anyone brought up a way to do this?

-=tvswebserver.com=-

simplymenotu’s picture

*NOTE* your editing a drupal core file. :-/

if (user_access('create forum topics')) {
      if (count($parents) > 1) {
        $output .= '<li>'. l(t('Post new forum topic.'), "node/add/forum/$tid")$
      }
    }

line added : if (count($parents) > 1) {

-s

JConnell’s picture

Thanks so much for this fix!

nvoyageur’s picture

It's not a good idea to hack the core. Instead copy the entire function that this line is in (i.e. theme_forum_display), paste it into your template.php file located in your theme folder, then rename the function to _forum_display. Then apply the edits that simplymenotu suggests.

Now when you update drupal you don't have to go back and fix the forum.module file and you know where all your changes are at.

Thanks simpymenotu, it's what I was looking for to clean up the forum.

Shane
BWCA

guillaumeduveau’s picture

Thanks Spydor for helping us develop in the Drupal way.

dhestlund’s picture

Forgive me, I'm neither a themer nor a developer (yet), just a humble content manager. I tried putting this at the end of my template.php:

/**
 * Format the forum body (and block containers from allowing posts).
 *
 * @ingroup themeable
 */
function _forum_display($forums, $topics, $parents, $tid, $sortby, $forum_per_page) {
  global $user;
  // forum list, topics list, topic browser and 'add new topic' link

  $vocabulary = taxonomy_get_vocabulary(variable_get('forum_nav_vocabulary', ''));
  $title = $vocabulary->name;

  // Breadcrumb navigation:
  $breadcrumb = array();
  if ($tid) {
    $breadcrumb[] = array('path' => 'forum', 'title' => $title);
  }

  if ($parents) {
    $parents = array_reverse($parents);
    foreach ($parents as $p) {
      if ($p->tid == $tid) {
        $title = $p->name;
      }
      else {
        $breadcrumb[] = array('path' => 'forum/'. $p->tid, 'title' => $p->name);
      }
    }
  }

  drupal_set_title(check_plain($title));

  $breadcrumb[] = array('path' => $_GET['q']);
  menu_set_location($breadcrumb);

  if (count($forums) || count($parents)) {
    $output  = '<div id="forum">';
    $output .= '<ul>';

    if (user_access('create forum topics')) {
      if (count($parents) > 1) {
      $output .= '<li>'. l(t('Post new forum topic.'), "node/add/forum/$tid") .'</li>';
      }
    }
    else if ($user->uid) {
      $output .= '<li>'. t('You are not allowed to post a new forum topic.') .'</li>';
    }
    else {
      $output .= '<li>'. t('<a href="@login">Login</a> to post a new forum topic.', array('@login' => url('user/login', drupal_get_destination()))) .'</li>';
    }
    $output .= '</ul>';

    $output .= theme('forum_list', $forums, $parents, $tid);

    if ($tid && !in_array($tid, variable_get('forum_containers', array()))) {
      $output .= theme('forum_topic_list', $tid, $topics, $sortby, $forum_per_page);
      drupal_add_feed(url('taxonomy/term/'. $tid .'/0/feed'), 'RSS - '. $title);
    }
    $output .= '</div>';
  }
  else {
    drupal_set_title(t('No forums defined'));
    $output = '';
  }

  return $output;
}

It didn't do anything. It didn't break the site either, which is nice. What am I doing wrong?
___
Drupal is a perfectly cromulent word.

guillaumeduveau’s picture

This works but only if the forum is at the 2d level, in a container which is at the 1st level on the forums page.

logicexpertise’s picture

if ($tid && !in_array($tid, variable_get('forum_containers', array()))) {
    $output .= '<div id="new-forum-post">'. l(t('Post new forum topic.'), "node/add/forum/$tid") .'</div>';
}

I haven't super-tested it though, so YMMV.

farez’s picture

Here's another way (tested on Drupal 6.1 only):

1. Copy the forums.tpl.php file from the forum module folder into your theme folder

2. Change the line that says

<?php print theme('links', $links); ?>

to

<?php if ($topics) { print theme('links', $links); } ?>

3. Save the file and clear the cache

Basically, this template checks that the topics are listed before rendering the 'Post a new topic' link. If you're viewing the container, $topics will not be set, so the link won't render.

Copying the forums.tpl.php file to your template folder ensures that future Drupal upgrades do not interfere with your amendments, because you're not modifying core files.

Hope that helps.

Farez

fehin’s picture

subscribing

spacereactor’s picture

subscribing

bdds’s picture

Hi, my web designer made me a site with forum, I am an admin, but whoever visits the forum page can post NEWTOPIC, without even logging in. So as to prevent spammers.

Can someone please help me with disabling that feature from the admin side.

Thanks

lias’s picture

thanks Farez, works great!

vitis’s picture

Farez - Thank you for this snippet! Works like a charm, and simple.

Rob T’s picture

Worked in my 6.16. Thanks, Farez.

volongoto’s picture

Great post Farez. Thanks!

pumpkinkid’s picture

Anyone have any idea how to get this to work on D7?

PittMarson’s picture

Same problem with Drupal 7.
I know I could modify or override the forum methods, but it MUST be a frequently requested feature to disable this link and its action.

[edit] : I removed my container, just to try, and to have only a list of forums in /forum.
But it still displays this link, so anyone can post at the root of the forum tree ! I really don't understand the reason of this useless and mandatory feature.

Someone please ?

Thanks in advance,

Pitt

paulandrewmarchand@yahoo.com’s picture

Go to forum.module and change

if ($root_path == 'forum' || $root_path == 'forum/%') {

On line 168 to

if ($root_path == 'forum/%') {

That worked for me. Does anyone see a problem with that?

pumpkinkid’s picture

Other than having to re-do that change every time there is an update? no...

cparker15’s picture

That would only hide the action link from the root /forum listing. In order to hide the link on container listings, as well, you're also going to have to do a check to see if the current $forum_term is a container.

Below is an updated forum_menu_local_tasks_alter() that will achieve the desired result. Unfortunately, this change will be lost any time Drupal is updated. This change would ideally be merged into forum.module by a Drupal developer.

/**
 * Implements hook_menu_local_tasks_alter().
 */
function forum_menu_local_tasks_alter(&$data, $router_item, $root_path) {
  global $user;

  // Add action link to 'node/add/forum' on 'forum' sub-pages.
  if ($root_path == 'forum/%') {
    $tid = (isset($router_item['page_arguments'][0]) ? $router_item['page_arguments'][0]->tid : 0);
    $forum_term = forum_forum_load($tid);
    if ($forum_term) {
      $containers = variable_get('forum_containers', array());
      if (!in_array($forum_term->tid, $containers)) {
        $links = array();
        // Loop through all bundles for forum taxonomy vocabulary field.
        $field = field_info_field('taxonomy_forums');
        foreach ($field['bundles']['node'] as $type) {
          if (node_access('create', $type)) {
            $links[$type] = array(
              '#theme' => 'menu_local_action',
              '#link' => array(
                'title' => t('Add new @node_type', array('@node_type' => node_type_get_name($type))),
                'href' => 'node/add/' . str_replace('_', '-', $type) . '/' . $forum_term->tid,
              ),
            );
          }
        }
        if (empty($links)) {
          // Authenticated user does not have access to create new topics.
          if ($user->uid) {
            $links['disallowed'] = array(
              '#theme' => 'menu_local_action',
              '#link' => array(
                'title' => t('You are not allowed to post new content in the forum.'),
              ),
            );
          }
          // Anonymous user does not have access to create new topics.
          else {
            $links['login'] = array(
              '#theme' => 'menu_local_action',
              '#link' => array(
                'title' => t('<a href="@login">Log in</a> to post new content in the forum.', array(
                  '@login' => url('user/login', array('query' => drupal_get_destination())),
                )),
                'localized_options' => array('html' => TRUE),
              ),
            );
          }
        }
        $data['actions']['output'] = array_merge($data['actions']['output'], $links);
      }
    }
  }
} 
bluegray’s picture

For D7: add the following to your theme template.php.

/**
 * Implements hook_menu_local_tasks_alter().
 */
function mytheme_menu_local_tasks_alter(&$data, $router_item, $root_path) {
  if ($root_path == 'forum' || $root_path == 'forum/%') {
    // Remove topic action links if it's a container forum
    $container = (isset($router_item['page_arguments'][0]) ? $router_item['page_arguments'][0]->container : 0);
    if (!empty($container)) {
      unset($data['actions']['output']['forum']);
    }
  }
}
sandwormblues’s picture

This is great. It needs to be written into core imho. The forum should really work out of the box! I feel like it's been neglected and there hasn't been any improvement since d5 or d6.

sandwormblues’s picture

Also, i don't think i should have to add a contributed module (taxonomy access control) in order to allow users to post topics. Without this feature, core forum is essentially broken. i don't mean to sound ungrateful to the developers; it's a great module and i'm using it a LOT, so thank you! I'm just saying there is clearly still work to do on the core module, and the fixes seem simple enough that they could easily be implemented by D7.9.

matt.rad’s picture

Thanks for this. It clears up the problem, but now my site is throwing this error: "Notice: Undefined property: stdClass::$container" Any ideas on how to fix it?

Edy Gorbacev’s picture

its work..!! subscribe!!

paintingguy’s picture

I need the forum containers but wish they weren’t part of the add new topic. When adding a new topic it’s confusing for people. This should be fixed.
Wish this was fixed in Drupal 9