You are here

function _spaces_feature_menu_tree in Spaces 5

Recurses down the menu cache and builds a menu tree for a given feature.

2 calls to _spaces_feature_menu_tree()
spaces_features_labels in ./spaces_admin.inc
Menu customization form.
spaces_features_menu in ./spaces.module
returns a keyed array of features split by public/private/group-agnostic TODO: can this be optimized? maybe if we store our data differently : |

File

./spaces.module, line 1140

Code

function _spaces_feature_menu_tree($feature, $item = null, $gid = null) {
  global $_menu;
  $inet_menu = array();
  if (!$item) {

    // retrieve the  menu item from cache
    $path = current($feature->menu);

    // Currently only the first menu item is supported (and its children)
    $mid = $_menu['path index'][$path];
    $item = $_menu['items'][$mid];
    if (context_get('spaces', 'feature') == $feature->value) {
      $inet_menu['attributes'] = array(
        'class' => 'active',
      );
    }
  }

  // Check the item['type'] bitmask
  if ($item['access'] && $item['type'] & MENU_NORMAL_ITEM) {
    $inet_menu['title'] = spaces_custom_menu('label', $item['path'], $gid) ? spaces_custom_menu('label', $item['path'], $gid) : $item['title'];
    $inet_menu['#weight'] = spaces_custom_menu('weight', $item['path'], $gid) ? spaces_custom_menu('weight', $item['path'], $gid) : 0;
    $inet_menu['href'] = $item['path'];
    if ($item['children']) {
      foreach ($item['children'] as $mid) {
        $child = _spaces_feature_menu_tree($feature, $_menu['items'][$mid], $gid);
        if ($child) {
          $inet_menu['children'][$child['href']] = $child;
        }
      }

      // Children if they exist
      if (is_array($inet_menu['children'])) {
        uasort($inet_menu['children'], "_element_sort");
      }
    }
  }
  return $inet_menu;
}