diff --git a/template.php b/template.php index 65c1ded..1077d4a 100644 --- a/template.php +++ b/template.php @@ -136,41 +136,50 @@ function zurb_foundation_field__taxonomy_term_reference($variables) { } /** - * Implements theme_links() targeting the main menu specifically - * Outputs Foundation Nav bar http://foundation.zurb.com/docs/navigation.php - * + * Implements theme_menu_tree__MENU_NAME(). + * @param $variables + * @return string */ -function zurb_foundation_links__system_main_menu($vars) { - // Get all the main menu links - $menu_links = menu_tree_output(menu_tree_all_data('main-menu')); +function zurb_foundation_menu_tree__main_menu($variables) { + return '
'; +} - // Initialize some variables to prevent errors - $output = ''; +/** + * Implements theme_menu_link(). + * @param array $variables + * @return string + */ +function zurb_foundation_menu_link(array $variables) { + $element = $variables['element']; $sub_menu = ''; + $foundation_classes = array('active-trail', 'has-dropdown'); - foreach ($menu_links as $key => $link) { - // Add special class needed for Foundation dropdown menu to work - !empty($link['#below']) ? $link['#attributes']['class'][] = 'has-flyout' : ''; - - // Render top level and make sure we have an actual link - if (!empty($link['#href'])) { - $output .= '' . l($link['#title'], $link['#href']); - // Get sub navigation links if they exist - foreach ($link['#below'] as $key => $sub_link) { - if (!empty($sub_link['#href'])) { - $sub_menu .= '
  • ' . l($sub_link['#title'], $sub_link['#href']) . '
  • '; - } - } - $output .= !empty($link['#below']) ? ' ' : ''; + foreach ($element['#attributes']['class'] as $key => $element_class) { + if (!in_array($element_class, $foundation_classes)) { + unset($element['#attributes']['class'][$key]); + } + } - // Reset dropdown to prevent duplicates - unset($sub_menu); - $sub_menu = ''; + if (!count($element['#attributes']['class'])) { + unset($element['#attributes']['class']); + } else { + $element['#attributes']['class'] = array_values($element['#attributes']['class']); + } - $output .= ''; + if ($element['#below']) { + // remove theme wrapper to prevent core drupal menu classes + foreach ($element['#below'] as $key => $element_below) { + unset($element['#below'][$key]['#theme_wrappers']); } + + $element['#attributes']['class'][] = 'has-dropdown'; + + unset($element['#below']['#theme_wrappers']); + $sub_menu = ''; } - return ''; + + $output = l($element['#title'], $element['#href'], $element['#localized_options']); + return '' . $output . $sub_menu . "\n"; } /**