Ankh2054
Ankh2054

Reputation: 1153

Drupal - Hide block with PHP code

I've installed the module - http://drupal.org/project/formblock (Enables the presentation of node creation forms in blocks)

I've enabled it for a particular content type and then exposed that block, to show when an Organic Group node is being viewed.

What I would like to do is hide that block if the current logged in user, is not the author of the Organic Group node being viewed. i.o.w I only want the organic group author to see that block.

thanks in advance :)

Upvotes: 2

Views: 2732

Answers (1)

wiifm
wiifm

Reputation: 3798

You can use 'PHP block visibility settings' to achieve what you want here. Using PHP you can query the database, and check whether the logged in user is the same user that created the node in the organic group.

There is an example already on drupal.org that I have adapted (you will probably need to customise this further) -

<?php
// check og module exists
if (module_exists('og')){
    // check user is logged in
    global $user;
    if ($user->uid) {
        // check we've got a group, rights to view the group,
        // and of type "group_type" - change this to whichever group you want to restrict the block to
        // or remove the condition entirely
        if (($group = og_get_group_context()) && node_access('view', $group) && ($group->type == 'group_type') ) {
            // check current user is a team admin as they should get access
            if (og_is_node_admin($group)) {
                return TRUE;
            }
            // check to see if the current user is the node author
            if (arg(0) == 'node' && is_numeric(arg(1))) {
                $nid = arg(1);
                $node = node_load(array('nid' => $nid));
                if ($node->uid == $user->uid) {
                    return TRUE;
                }
            }
        }
    }
}
return FALSE;
?>

Upvotes: 4

Related Questions