You are here

function custom_breadcrumbs_theme_menu_item in Custom Breadcrumbs 7.2

Same name and namespace in other branches
  1. 6.2 custom_breadcrumbs.module \custom_breadcrumbs_theme_menu_item()

Theme Menu Item.

@todo Please document this function.

See also

http://drupal.org/node/1354

1 string reference to 'custom_breadcrumbs_theme_menu_item'
custom_breadcrumbs_theme_registry_alter in ./custom_breadcrumbs.module
Implements hook_theme_registry_alter().

File

./custom_breadcrumbs.module, line 1082
Main file for the Custom breadcrumbs.

Code

function custom_breadcrumbs_theme_menu_item($link, $has_children, $menu = '', $in_active_trail = FALSE, $extra_class = NULL) {
  global $theme;
  static $function;
  if (!isset($function)) {
    $registry = variable_get('custom_breadcrumbs_menu_theme', array());
    $function = isset($registry[$theme]) ? $registry[$theme]['menu_item'] : 'theme_menu_item';
  }

  /* When theme('menu_item') is called, the menu tree below it has been
   * rendered already. Since we are done on this recursion level,
   * one element must be popped off the stack.
   */
  $item = _custom_breadcrumbs_menu_stack();

  // If there are children, but they were not loaded...
  if ($has_children && !$menu) {

    // Load the tree below the current position.
    $tree = _custom_breadcrumbs_menu_subtree($item);
    $force_active_trail = FALSE;
    if (!empty($tree)) {
      foreach ($tree as $sub => $data) {
        if (custom_breadcrumbs_in_active_trail($data['link'])) {
          $force_active_trail = TRUE;
        }
        else {
          $belows = (array) $data['below'];
          foreach ($belows as $id => $below) {

            // Descend...
            if (custom_breadcrumbs_in_active_trail($below['link'])) {
              $force_active_trail = TRUE;
            }
            else {
              unset($tree[$sub]['below'][$id]);
            }
          }
        }
      }
    }
    if ($force_active_trail) {

      // Render it...
      $menu = menu_tree_output($tree);
      $in_active_trail = TRUE;
    }

    // Sanitize tree. If we found no children, the item has none.
    if (!$menu) {
      $has_children = FALSE;
    }
  }

  // If the current item can expand, and is neither saved as open nor in the
  // active trail, close it.
  if ($menu && !$in_active_trail) {
    $extra_class .= ' collapsed start-collapsed ';
  }

  // Pass the altered variables to the normal menu themer.
  return $function($link, $has_children, $menu, $in_active_trail, $extra_class);
}