Drupal sites can have a wide range of content and it is sometimes useful to know what kind of content is being displayed as well as whether it was related to a group. The following PHP code can be pasted into a custom block and placed above the content. It will then display the content type to the upper right and the group to the left. The content type is a link to the view that normally displays other content of the same type. Likewise, the group name displays the group page and the prefix link is to the view that displays the list of similar groups.

I happened to have two group types: Group and Company. The prefix indicates the appropriate type. Obviously, if you have only one type then you don't need the conditional.

$nid=arg(1);
$isnode=(arg(0)=='node') && is_numeric($nid);
if ( $isnode AND $nid ) {
  $node=node_load($nid);
  $ntype=node_get_types('name',$node);
  $link=$node->type;
  if ( $link == 'group' ) {
    $link='og';
  } 
  if ( $ntype == 'Book page' ) {
    $ntype='Book';
  }
  echo "<div href='/$link'>$ntype</a></div>";
}
if ( function_exists('og_get_group_context')) {
  $group=? og_get_group_context() ;
  if ($group) {
    $gid=$group->nid;
    if ( ! ($isnode AND ($gid==$nid))) {
      $gnode=node_load($gid);
      $title=$group->title;
      $prefix=$gnode->type=='company'
         ?"<a href='companies'>Company:</a>"
         :"<a href='og'>Group:</a>";
      echo "<h2 class='title'>$prefix <a class='current_group_title' href='/node/$gid'>$title</a></h2>";
    }
  }
}

The following needs to be added to a CSS file, probably the theme CSS file. Alternatively, the style information can be hard coded into the HTML text generated by PHP code listed above. This particular style simply puts an inset box around the node type to make it stand out. Likewise, the font size for the text is small so it does not over power the node title.

h2 .current_group_prefix, h2 .current_group_title {
  font-size: 10pt;
}

.cg_node_type {
  float: right;
}

.cg_node_type a {
  font-size: 10pt;
  font-style: bold;
  border-style: inset;
  padding: 0px 2px 1px 2px;
}

Comments

rubyji’s picture

I'm trying to create a block that will determine whether the current user is a member of any of the groups that the current node is in. (Then it will display an "edit this page" if the node type = wiki.)

It seems like the code above might get me partway there, but I'm not handy enough with PHP to pull it together. Does anyone have suggestions?