You are here

function _advanced_menu_submenu_trees in Advanced Menu 7

Helper function to build out sub-menus for block display.

1 call to _advanced_menu_submenu_trees()
advanced_menu_submenu_block_view_alter in submenu/advanced_menu_submenu.module
Implements hook_block_view_alter().

File

submenu/advanced_menu_submenu.module, line 220
Provides advanced menu submenus.

Code

function _advanced_menu_submenu_trees($item) {
  $new_items = $item;
  $alter_path = '';
  if (is_array($new_items)) {
    if (isset($item['#original_link']) && $item['#original_link']['router_path'] == 'advanced-menus/sub-menus/%') {
      $original_path = explode('/', $item['#original_link']['link_path']);
      $alter_path = array_pop($original_path);
      $original_path = implode('/', $original_path);
      $new_items = menu_tree($alter_path);
      foreach ($new_items as $key => $new_item) {
        $new_items[$key] = _advanced_menu_submenu_trees($new_item);
      }
    }
    if (!empty($new_items['#below'])) {
      foreach ($new_items['#below'] as $key => $below) {
        $new_data = _advanced_menu_submenu_trees($below);
        if (is_array($new_data)) {
          if (isset($new_items['#below'][$key]['#original_link']) && $new_items['#below'][$key]['#original_link']['router_path'] == 'advanced-menus/sub-menus/%') {
            unset($new_items['#below'][$key]);
          }
          $new_items['#below'] = array_merge($new_items['#below'], $new_data);
        }
        else {
          $new_items['#below'][$key] = $new_data;
        }
        if (is_array($new_data) && _advanced_menu_submenu_is_active($new_data)) {
          $new_items['#attributes']['class'][] = 'active-trail';
          $new_items['#localized_options']['attributes']['class'][] = 'active-trail';
        }
      }
    }
  }
  return $new_items;
}