You are here

function spaces_features_menu in Spaces 5.2

Same name and namespace in other branches
  1. 5 spaces.module \spaces_features_menu()
  2. 6 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.

1 call to spaces_features_menu()
_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 1037

Code

function spaces_features_menu() {
  static $menu;
  if (!isset($menu)) {
    $menu = array();
    $space = spaces_get_space();
    if ($space) {
      $features = spaces_features($space->type);
      $active_feature = context_get('spaces', 'feature');
      $depth = 1;

      // Loop once through features to build menu set
      foreach ($space->features as $feature => $value) {
        if ($value != SPACES_FEATURE_DISABLED && $space
          ->feature_access($feature) && isset($features[$feature]->spaces['menu'])) {

          // Customize the menu
          $feature_menu = $features[$feature]->spaces['menu'];
          $feature_menu = space_customizer_menu::customize($space, $feature, $feature_menu);

          // Collect menu items
          foreach ($feature_menu as $path => $item) {
            $args = explode('/', $path);
            $item['href'] = $path;
            $item['children'] = array();
            $item['depth'] = count($args);
            $item['args'] = $args;
            if ($item['depth'] == 1 && $feature == $active_feature) {
              $item['attributes'] = array(
                'class' => 'active',
              );
            }
            else {
              if ($item['depth'] > $depth) {
                $depth = $item['depth'];
              }
            }
            $menu[$path] = $item;
          }
        }
      }

      // Second loop to tree the menu
      while ($depth >= 1) {
        foreach ($menu as $path => $item) {
          if ($item['depth'] == $depth) {
            $args = implode('/', array_slice($item['args'], 0, $depth - 1));
            if ($depth > 1) {
              if (isset($menu[$args])) {
                unset($item['depth']);
                unset($item['args']);
                $menu[$args]['children'][$path] = $item;
              }
              unset($menu[$path]);
            }
            else {
              unset($menu[$path]['args']);
              unset($menu[$path]['depth']);
            }
          }
        }
        $depth--;
      }
    }
  }
  return $menu;
}