You are here

function _menu_breadcrumb_get_menus in Menu Breadcrumb 6

Same name and namespace in other branches
  1. 7 menu_breadcrumb.module \_menu_breadcrumb_get_menus()

Get the menu selection configuration.

Return value

Array of menu selections and weights.

2 calls to _menu_breadcrumb_get_menus()
menu_breadcrumb_admin_settings_form in ./menu_breadcrumb.module
Menu breadcrumb admin settings form.
menu_breadcrumb_menu_list in ./menu_breadcrumb.module
Get the menu/selection list.

File

./menu_breadcrumb.module, line 77
The main file for the menu_breadcrumb module.

Code

function _menu_breadcrumb_get_menus() {
  static $menus;
  if (!isset($menus)) {

    // Fetch stored or default settings.
    $menus = variable_get('menu_breadcrumb_menus', _menu_breadcrumb_default_menu());

    // Load the pattern match cache (to avoid any unnecessary regex matching).
    // Submitting the settings form requires us to rebuild this cache, as
    // the patterns may have changed.
    $match_cache = variable_get('menu_breadcrumb_pattern_matches', array());
    $match_cache_rebuild = variable_get('menu_breadcrumb_pattern_matches_rebuild', FALSE);
    if ($match_cache_rebuild) {
      variable_set('menu_breadcrumb_pattern_matches_rebuild', FALSE);
      $match_cache_old = $match_cache;
      $match_cache = array();
    }
    else {
      $match_cache_old = array();
    }

    // Find new/unknown menus. If rebuilding the pattern match cache,
    // we also treat previously-matched menus (i.e. those currently
    // 'replaced' by a pattern) as new.
    $drupal_menu_names = menu_get_names();
    $unknown_menu_names = array_diff($drupal_menu_names, array_keys($menus), array_keys($match_cache));
    if ($unknown_menu_names) {
      $new_menus = _menu_breadcrumb_process_unknown_menus($unknown_menu_names, $menus, $match_cache_old, $match_cache_rebuild);
    }
    else {
      $new_menus = array();
    }

    // Check new menus against the patterns.
    if ($match_cache_rebuild) {

      // We need to check all menus (old and new), as the
      // patterns may have been modified.
      $new_menus = array_merge($new_menus, $menus);
      $menus = array();
    }
    if ($new_menus) {

      // $menus and $match_cache are updated by reference.
      _menu_breadcrumb_process_new_menus($new_menus, $menus, $match_cache, $match_cache_rebuild);
    }

    // Remove any defunct menu names. Only visible if we are showing
    // the admin settings form, so don't waste time processing this
    // otherwise.
    if ($_GET['q'] == 'admin/settings/menu_breadcrumb') {
      $current_menu_names = array_merge($drupal_menu_names, array_unique($match_cache), array(
        'menu_breadcrumb_default_menu',
      ));
      $menus_current = array_intersect(array_keys($menus), $current_menu_names);
      $menus = array_intersect_key($menus, array_flip($menus_current));
    }
  }
  return $menus;
}