You are here

function commons_subgroups_views_post_render in Drupal Commons 6.2

Implementation of hook_views_pre_view()

File

modules/features/commons_subgroups/commons_subgroups.module, line 22

Code

function commons_subgroups_views_post_render(&$view, &$output, &$cache) {

  // Viewing a listing of subgroups
  if ($view->name == 'subgroups_main_listing' && $view->current_display == 'page_2') {
    og_subgroups_include('tree');

    // Start the breadcrumb
    $breadcrumb = array();
    $breadcrumb[] = l(t('Home'), '<front>');
    $breadcrumb[] = l(t('Groups'), 'groups');

    // Extract the parent group nid
    $parent = $view->args[0];

    // Fetch the tree for the parent in the argument
    $tree = og_subgroups_get_group_tree((object) array(
      'nid' => $parent,
    ));
    if ($tree) {

      // Flatten the tree so we can easily iterate
      $tree = og_subgroups_flatten_tree($tree);
      foreach ($tree as $nid => $group) {

        // If we're at the parent group, provide a non-link crumb, and stop here
        if ($parent == $nid) {
          $breadcrumb[] = check_plain($group->title);
          break;
        }
        else {
          $breadcrumb[] = l(check_plain($group->title), "groups/sub/{$group->nid}");
        }
      }
    }
    else {
      if ($parent = node_load($parent)) {

        // Just in case..
        if (og_is_group_type($parent->type)) {
          $breadcrumb[] = $parent->title;
        }
      }
    }

    // Override the breadcrumb
    drupal_set_breadcrumb($breadcrumb);
  }
}