You are here

function _advanced_menu_submenu_cycle in Advanced Menu 7

Recursive Helper function to cycle through the menus and determine what links where.

1 call to _advanced_menu_submenu_cycle()
_advanced_menu_submenu_menus in submenu/advanced_menu_submenu.module
Helper function to determine what menus can be linked to from a given menu.

File

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

Code

function _advanced_menu_submenu_cycle($menu, $default_value = NULL) {
  $menus = array();
  $menus[$menu] = $menu;
  $query = db_select('menu_links', 'm')
    ->fields('m', array(
    'menu_name',
  ))
    ->condition('link_path', 'advanced-menus/sub-menus/' . $menu, '=')
    ->execute();
  if ($query) {
    while ($record = $query
      ->fetchAssoc()) {
      $p_menus = _advanced_menu_submenu_cycle($record['menu_name']);
      $menus = array_merge($menus, $p_menus);
    }
  }
  if (!empty($default_value)) {
    $query = db_select('menu_links', 'm')
      ->fields('m', array(
      'link_path',
    ))
      ->condition('link_path', 'advanced-menus/sub-menus/%', 'LIKE')
      ->condition('link_path', $default_value, '!=')
      ->condition('menu_name', $menu, '=')
      ->execute();
    if ($query) {
      while ($record = $query
        ->fetchAssoc()) {
        $p_path = explode('/', $record['link_path']);
        $p_menu = array_pop($p_path);
        $p_menus = array(
          $p_menu,
        );
        $menus = array_merge($menus, $p_menus);
      }
    }
  }
  return $menus;
}