background image
HomeRecent PostsDrupalSearchTagsRSSContactAboutAccount

Adding block visibility code to show the Organic Groups Recent Members block on group node types

Eric.London's picture

The Organic Groups Views Integration module comes with a bunch of useful views related to groups and their members. I assigned the "Recent members" block view to a region of my theme, and the block appeared on all group nodes and nodes that belong to a group. For the Drupal site I was working on, it was desired to only appear on the group nodes (not the nodes that belong to groups). No worries, you can always add block visibility code to determine when to show the block.

I went to the blocks admin screen (admin/build/block) and clicked configure for this block. Scroll down to the fieldset titled "Page specific visibility settings". I choose the radio option "Show if the following PHP code returns TRUE (PHP-mode, experts only)." and added the following PHP snippet:

<?php
if (function_exists('_MYMODULE_block_visibility_og_members'))
  return
_MYMODULE_block_visibility_og_members();
return
false;
?>

Next, I added a function in my module to handle the request.

<?php
function _MYMODULE_block_visibility_og_members() {
 
// lookup node id from query string
 
$path = drupal_lookup_path('source', $_REQUEST['q']);

 
// ensure the page is a node
 
if (substr($path,0,5)=='node/') {
   
// load node
   
$node = node_load(substr($path,5));

   
// check if node type is a group node
   
return og_is_group_type($node->type);
  }
  return
false;
}
?>

Now, the block only appears on group node types.

its realy good

Thanks, for the good articles ...I am very intiresting..