Hi all!
I'm using Sections 6.x-1.x-dev together with Organic Groups (6.x-2.x-dev).
I'm trying with to switch theme if the user who is visiting the group node is also a member of the group.
(I can't just use OG theme functions because I need two different themes depending on the user status)
To do this I check if the user logged in has the current node among the groups he is member of.
It doesn't work - but the code I'm using works for blocks, so I'm a bit lost.
The following code adapted from http://drupal.org/node/201543#comment-661614 makes the block show up correctly if a user is member of the group:
<?php
global $user;
$nid = arg(1);
if(arg(0) == 'node' && is_numeric($nid)) {
if (in_array($nid, $user->og_groups) {
return TRUE;
}
}
?>
This one adapted from http://drupal.org/node/201543#comment-1260103 does the trick as well:
global $user;
$nid = arg(1);
if(arg(0) == 'node' && is_numeric($nid)) {
$account = user_load(array('uid' => $user->uid));
if (isset($account->og_groups[$nid])) {
return TRUE;
}
}
I'm really no expert in PHP, but it seems that somehow Sections skips the in_array check, returning always TRUE: every node of any type gets the section theme, regardless of the user being a member of the group or not and even if the nodes are not group nodes.
Any suggestion? Alternative methods, places to look into...?
Thank you all!
Comments
Comment #1
smoothk commentedI thought I'd change the category to bug report since it looks like it's Sections that is not working properly. I'm still investigating the issue doing more tests but haven't come to anything new.
Comment #2
smoothk commentedIt turned out that it was a problem with
which is an array of arrays, so the in_array() function doesn't work correctly.
I transformed it into a simple array with array_keys() and voilà! All good.
Comment #3
smoothk commentedForgot to change issue status. Done!
Comment #4
hass commented