You are here

function node_gallery_set_breadcrumb in Node Gallery 6.3

Set the current breadcrumb trail while also respecting menu customizations and access controls. Any menu items that the current user does not have access to will be skipped, and if no items are accessible the breadcrumb will be left unchanged. If the breadcrumb is set, a "Home" crumb will be included automatically.

Parameters

$trail: An array of system paths.

Return value

TRUE if the breadcrumb was set, or FALSE if no items in $trail were accessible by the current user.

4 calls to node_gallery_set_breadcrumb()
node_gallery_form_alter in ./node_gallery.module
Implements hook_form_alter().
node_gallery_list_galleries in ./node_gallery.pages.inc
Displays the gallery summary page, which is a user-specified view.
node_gallery_set_user_breadcrumb in ./node_gallery.module
Set a Gallery breadcrumb for a given user ID.
_node_gallery_image_view in ./node_gallery.module
Attaches the image navigator to the image node's content.

File

./node_gallery.module, line 1361
Node gallery module file.

Code

function node_gallery_set_breadcrumb($trail, $node = NULL) {
  $crumbs = array();
  static $menu_title_cache = array();
  if (module_exists('og')) {
    if (!empty($node->nid)) {
      $group_node = og_determine_context_get_group($node);
      if ($group_node && !empty($node->og_groups)) {
        og_set_group_context($group_node);
        $crumbs = og_get_breadcrumb($group_node);
        if ($node->gid) {
          $gallery = node_load($node->gid);
          $crumbs[] = l($gallery->title, 'node/' . $gallery->nid);
        }
      }
    }
  }
  if (empty($crumbs)) {
    foreach ($trail as $path) {
      $menu_item = menu_get_item($path);

      // Use a static array to cache href->title mapping.
      // Thanks to http://drupal.org/project/custom_breadcrumbs for the pointers.
      $ckey = $menu_item['href'];
      if (!isset($menu_title_cache[$ckey])) {
        $result = db_query("SELECT mlid FROM {menu_links} WHERE link_path = '%s'", $menu_item['href']);
        while ($menu_link = db_fetch_array($result)) {
          $menu_loaded_link = menu_link_load($menu_link['mlid']);
          $menu_title_cache[$ckey] = $menu_loaded_link['title'];
        }
        if (!isset($menu_title_cache[$ckey])) {

          // There is no menu link to that path, use the item.
          $menu_title_cache[$ckey] = $menu_item['title'];
        }
      }
      if ($menu_item['access']) {

        // We have to use $path here as we want the real URL, not the router path.
        $crumbs[] = l($menu_title_cache[$ckey], $path, array(
          'html' => TRUE,
        ));
      }
    }
  }
  if (!empty($crumbs)) {
    if ($crumbs[0] != l(t('Home'), NULL)) {
      array_unshift($crumbs, l(t('Home'), NULL));
    }
    $menu_item = menu_get_item();

    // @todo: This works well for OG, but non-OG tabs are still funky
    if (preg_match('/(upload|edit|sort|images)$/', $menu_item['path'])) {
      $crumbs[] = l($node->title, 'node/' . $node->nid);
    }
    drupal_set_breadcrumb($crumbs);
    return TRUE;
  }
  return FALSE;
}