You are here

function og_menu_block in Organic Groups Menu (OG Menu) 6

Same name and namespace in other branches
  1. 6.2 og_menu.module \og_menu_block()

Implementation of hook_block().

File

./og_menu.module, line 139
Integrates Menu with Organic Groups. Lots of menu forms duplication in OG context.

Code

function og_menu_block($op = 'list', $delta = 0) {
  if ($op == 'list') {
    $blocks[0] = array(
      'info' => t('OG Menu'),
      'cache' => BLOCK_NO_CACHE,
    );
    return $blocks;
  }
  else {
    if ($op == 'view') {

      // Get all groups associated with the current node
      $node = menu_get_object();
      $gids = array();
      if ($node) {
        if (og_is_group_post_type($node->type)) {
          $gids = $node->og_groups;
        }
        else {
          if (og_is_group_type($node->type)) {
            $gids = array(
              $node->nid,
            );
          }
        }
      }

      // If no group was found, fallback to the regular og_get_group_context
      // function. Unfortuantely, this function only returns one group.
      if (empty($gids)) {
        $group = og_get_group_context();
        $gids = array(
          $group->nid,
        );
      }
      $menus = og_menu_get_menus($gids);
      foreach ($menus as $menu) {
        $block = new stdClass();
        $block->subject = check_plain($menu['title']);
        $block->content = menu_tree($menu['menu_name']);
        $content .= theme('block', $block);
      }
      return array(
        'content' => $content,
      );
    }
  }
}