group context not set when viewing a forum post
liquidcms - October 4, 2009 - 00:58
| Project: | OG Forum |
| Version: | 6.x-2.x-dev |
| Component: | Code |
| Category: | bug report |
| Priority: | normal |
| Assigned: | paulbooker |
| Status: | reviewed & tested by the community |
Description
I thought this might get fixed when i switched from 6.x-1. to 6.x-2; but no luck
When i am viewing a forum post the group context is not set and therefore i don't get the Group Details block showing. Also, the breadcrumb is wrong:
however, other forum parts do do these right:
- viewing the Forum is correct
- viewing the list of forums is correct
- adding a post is correct
when editing a post; the bcrumb is also wrong and the details block is missing

#1
This seems to be working perfectly for me, can anyone else replicate this problem ?
#2
in another module i added this code in nodeapi hook to fix the problem:
case 'view':if ($node->type == "forum") {
$group = node_load($node->og_forum_nid);
og_set_group_context($group);
}
break;
#3
I just came here to post that very same issue. Same version.
#4
can you explain this? Which other module?
#5
sorry, i meant ANY module. I always have a tweaks module for every project i do to just add in various module tweaks - i added it there.
#6
How do you add a tweaks module? Is there no way to change something in template.php instead?
#7
sorry.. little out of scope of this thread.. but tons of info on this site about module design
template.php; perhaps but not sure where... it might work inside node.tpl.php...
#8
Ok... I agree, creating a new module is definitely out of the scope of this thread!! lol
However, this still seems to be an issue directly related to this module - which shouldn't need another module to fix it. PaulBooker said this is working perfectly for him, which makes me wonder why it's not for me and the OP. That said, how can we fix this? (without an external module)
#9
Got it! Somehow missed this other issue that was previously posted: http://drupal.org/node/503622
In short, if forum topics are not permitted to be posted in a group, adding a forum topic will make you lose the group context. Odd.. I would guess you wouldn't be able to post the topic at all if there were no permissions for it.
I didn't mark this fixed, since it wasn't assigned to me, nor am I the original poster. But this cleared it up.
#10
nope, not my issue.. these posts are posted to a group.
and since my code : $group = node_load($node->og_forum_nid); returns a value; which allows me to fix this by simply setting the group context - it would seem to prove that it is in a group.
pretty sure this is still a bug in og_forum.
#11
Hey liquid,
When I had been posting forum topics, I was doing it from within the group, too. However, I shouldn't have been able to since I had forgotten to enable the permissions to do so (a separate issue). Since the permissions weren't set, they were losing the group context.
did you verify the permissions were there to allow forum topics to be posted to a group?
#12
again, as i said... $node->og_forum_nid is set on the post; which is why my hack works.. and also how it proves my posts are actually in the group forum.
#13
Yes, there's a bug here. Line 677 is this:
<?phpog_set_group_context(node_load($node->og_groups[0]));
?>
Which sometimes causes an undefined offset notice because the first element in the og_groups array is not always at 0. Can be fixed by:
<?phpog_set_group_context(node_load(current($node->og_groups)));
?>
But, as there's also a lot of redundant code in that part of the function, I think liquidcms' solution is good, with the addition that it should only be run when viewing a forum post as a page (also og_forum_nid will only be set for type == 'forum' so this conditional check is a bit safer), eg:
<?phpcase 'view':
// If we're viewing a forum post in a group forum, set that
// group as the context.
if (!empty($page) && isset($node->og_forum_nid)) {
$group = node_load($node->og_forum_nid);
og_set_group_context($group);
}
break;
?>
Patch attached (against 6.x-2.x-dev).
#14
I found 2 other references to $node->og_groups[0] in og_forum_nodeapi. Better to also change these to current($node->og_groups) as this won't produce an error/warning if $node->og_groups is an empty array. Updated patch attached.
There's quite a bit of refactoring required in this function though as FALSE will still be passed to og_forum_get_forum_container (instead of a $group_id) if og_groups is empty, $container will then be FALSE, etc. (eg. when the forum is not in a group):
<?php$container = og_forum_get_forum_container(current($node->og_groups));
?>
Not a big issue, just could be a little cleaner.
#15
very cool.. thanks for posting.
I'll try it out in lieu of my solution.
#16
Thanks Dazweeja
I'll get you patch committed to the development branch later today
For me the only the problem that needs to be fixed is ..
"when editing a post; the bcrumb is also wrong and the details block is missing"
Is this still a problem for others ?
Best,
Paul Booker
#17
Thanks for the patch - works great.
(also subscribing)