In my current project, i have a Forum topic "Announcements" that I only want certain roles to be able to create topics in.
Forum Access module allows me to specify that sort of access control. Advanced Forum however does not check for that sort of granularity when building "Create New topic" links and as a result "Create New XXX" links/buttons do appear in such forums, but when you click on them you do get "Access Denied" as dictated by Forum Access".

To overcome this I looked into function function advanced_forum_get_forum_post_links($tid) inside core-overrides.inc and found a place where these "Create New XXX" links are build:

 // Loop through all node types for forum vocabulary.
  foreach ($vocabulary->nodes as $type) {
    // Check if the current user has the 'create' permission for this node type.
    if (node_access('create', $type)) {
      // Fetch the "General" name of the content type.
      $node_type = node_get_types('name', $type);

      // Remove the word "Forum" out of "Forum topic" to shorten it.
      // @TODO: this is a little dodgy and may not work right with
      // translations. Should be replaced if there's a better way.
      $node_type = str_replace('Forum', '', $node_type);

      // Push the link with title and url to the array.
      $forum_types[$type] = array(
        'title' => t('New @node_type', array('@node_type' => $node_type)),
        'href' => 'node/add/'. str_replace('_', '-', $type) .'/'. $tid,
        'html' => TRUE);
    }
  }

So this is where link creation takes place. I wanted to avoid creating these "Create New XXX" links if Forum Access Module denies user "Create" access to this forum.
So I wrapped the above code segment in some boolean magic that really only matters if you have Forum Access Module installed

//by default we should check for create access
$check_create_access=TRUE;
if(module_exists('forum_access'))
{
	//if forum access allows creation in the forum, check create access
	//otherwise dont
	$check_create_access= forum_access_access($tid, 'create', NULL, TRUE);

}

if($check_create_access)
{
  // Loop through all node types for forum vocabulary.
  foreach ($vocabulary->nodes as $type) {
    // Check if the current user has the 'create' permission for this node type.
    if (node_access('create', $type)) {
      // Fetch the "General" name of the content type.
      $node_type = node_get_types('name', $type);

      // Remove the word "Forum" out of "Forum topic" to shorten it.
      // @TODO: this is a little dodgy and may not work right with
      // translations. Should be replaced if there's a better way.
      $node_type = str_replace('Forum', '', $node_type);

      // Push the link with title and url to the array.
      $forum_types[$type] = array(
        'title' => t('New @node_type', array('@node_type' => $node_type)),
        'href' => 'node/add/'. str_replace('_', '-', $type) .'/'. $tid,
        'html' => TRUE);
    }
  }
}

Comments

michelle’s picture

Thanks. Seems reasonable enough to add a check there.

Michelle

michelle’s picture

Status: Active » Fixed

I committed something along these lines, adapted to take into account changes in this code. I don't have Forum Access installed so it's untested to make sure it works but I tested to make sure it doesn't break anything.

Michelle

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

jsibley’s picture

Has anyone been able to test whether Michelle's changes work? I just installed advanced forum, cleared caches, and still see "Login to post new content in the forum".

Is modifying php really the only way to get rid of this? Are there any other settings I should be checking?

Thanks.