You are here

function spaces_features_menu in Spaces 6

Same name and namespace in other branches
  1. 5.2 spaces.module \spaces_features_menu()
  2. 5 spaces.module \spaces_features_menu()

Returns a links array in the theme_links() format of the current space's menu items for features accessible to the current user. Each item has a keyed array of children items if applicable.

Return value

Array of links.

2 calls to spaces_features_menu()
spaces_preprocess_page in ./spaces.module
_spaces_block_nav in ./spaces.module
Default navigation menu - you can create your own customized version using the spaces_features_menu() and theme_links() functions.

File

./spaces.module, line 1485

Code

function spaces_features_menu($space = NULL, $reset = FALSE) {
  static $cache;
  $cache = !isset($cache) ? array() : $cache;
  $space = empty($space) ? spaces_get_space() : $space;

  // Sanity check on our space object.
  if ($space && !empty($space->sid)) {

    // Cache by space type
    $cache[$space->type] = !isset($cache[$space->type]) ? array() : $cache[$space->type];
    if (!isset($cache[$space->type][$space->sid]) || $reset) {

      // Load up the spaces menu links
      $menu = menu_navigation_links('spaces');
      $menu = space_customizer_menu::customize($space, '', $menu);

      // Retrieve the menu cache for a path to feature mapping
      $menu_cache = cache_get('spaces_menu');
      $menu_cache = !$menu_cache ? spaces_menu_rebuild() : $menu_cache->data;

      // Sort the menu by feature weight & hide any items
      // for features that are not available (this **should**)
      // be handled by access control on the links' respective
      // menu callbacks, but awkward permissioning sometimes
      // makes it nice for these to be hidden manually.
      $weights = array_flip(array_keys($space->features));
      $weighted = array();
      foreach ($menu as $k => $item) {
        $feature = $menu_cache[$item['href']];
        if ($space
          ->feature_access($feature)) {

          // Retrieve path > feature > weight
          $menu[$k]['#weight'] = $weights[$feature];
        }
        else {
          unset($menu[$k]);
        }
      }
      uasort($menu, 'element_sort');
      $cache[$space->type][$space->sid] = $menu;
    }
    if (!empty($cache[$space->type][$space->sid])) {
      return $cache[$space->type][$space->sid];
    }
  }
  return array();
}