You are here

function opigno_breadcrumbs in Opigno 7

Get the breadcrumb trail for the current page.

1 call to opigno_breadcrumbs()
opigno_breadcrumbs_preprocess_page in modules/breadcrumbs/opigno_breadcrumbs.module
Implements hook_preprocess_page().

File

modules/breadcrumbs/opigno_breadcrumbs.module, line 18
Breadcrumbs module definition.

Code

function opigno_breadcrumbs() {

  // Get the default breadcrumb.
  $breadcrumb = drupal_get_breadcrumb();

  // Fetch the group from URL context.
  // If we are in group context, handle our own breadcrumbs.
  $group = og_context('node');
  if (!empty($group['gid']) && $group['group_type'] == 'node') {

    // If the group is for a course or a class, we add custom logic
    $node = node_load($group['gid']);
    if (in_array($node->type, array(
      'course',
      'class',
    ))) {

      // First, add the homepage.
      $new_breadcrumb = array(
        l(t('Home'), NULL),
      );

      // If the node is a course, check if it's part of a class and if the user is a member of this class.
      if ($node->type == 'course' && module_exists('opigno_class_app')) {
        $classes = opigno_breadcrumbs_get_classes_from_course($node->nid);
        if (!empty($classes)) {
          $class = array_shift($classes);
          $class = node_load($class);

          // If the user is member of this class, add it to the breadcrumb
          if (og_is_member('node', $class->nid)) {
            $new_breadcrumb[] = l($class->title, 'node/' . $class->nid);
          }
        }
      }

      // If the user is in a course or class context and not on the homepage, add the breadcrumbs.
      if (current_path() !== 'node/' . $node->nid) {

        // Add the course itself.
        $group_title = opigno_breadcrumbs_get_group_title($group['gid']);
        $new_breadcrumb[] = l($group_title, "node/{$group['gid']}");

        // Ask other modules for breadcrumbs.
        $module_breadcrumbs = module_invoke_all('opigno_breadcrumbs', $group['gid']);
        if (!empty($module_breadcrumbs)) {
          $new_breadcrumb = array_merge($new_breadcrumb, $module_breadcrumbs);
        }
      }

      // Set the new trail.
      $breadcrumb = $new_breadcrumb;
    }
  }
  return theme_breadcrumb(array(
    'breadcrumb' => $breadcrumb,
  ));
}