Declaring Block for a Different Content Type
tonyp001 - April 30, 2008 - 19:27
I'm writing a module that interacts with Organic Groups. One thing I'm trying to do is create a block that appears whenever the "group" content type is shown. I would like for the block to appear when the user enables my module and disappear when its disabled.
I was thinking I could use the nodeapi and add the block when someone views the "group" content type, but I wasn't sure how to declare a block for a content type that wasn't my own...
Does anyone have any idea how this could be done?
Any help would be appreciated.
Thanks.

hook_block
Just use hook_block normally, but only load your block under certain conditions.
OG does this, so look at og_block() -- there is even some logic there for determining when you are viewing an OG page. See og_block_details(), for instance.
<?phpfunction og_block_details() {
// only display group details if we have a group context
if (($node = og_get_group_context()) && node_access('view', $node)) {
// allow other og-enabled node types to provide their own block details
$block = module_invoke($node->type,'og_block_details',$node);
if (!$block) {
$block = og_og_block_details($node);
}
return $block;
}
}
?>
--
http://ken.therickards.com