Skip to content

Instantly share code, notes, and snippets.

@aastrong
Created April 16, 2015 17:12
Show Gist options
  • Save aastrong/355f0d94ebf762d158aa to your computer and use it in GitHub Desktop.
Save aastrong/355f0d94ebf762d158aa to your computer and use it in GitHub Desktop.
Patch to bring back megamenu to wet-boew
diff --git a/templates/menu/menu-link.func.php b/templates/menu/menu-link.func.php
index 3a5285c..cfda60f 100644
--- a/templates/menu/menu-link.func.php
+++ b/templates/menu/menu-link.func.php
@@ -45,7 +45,7 @@ function wetkit_bootstrap_menu_link(array $variables) {
/**
* Overrides theme_menu_tree().
*/
-function wetkit_bootstrap_menu_link__menu_block__main_menu(&$variables) {
+function wetkit_bootstrap_menu_link__menu_block__megamenu(&$variables) {
$element = $variables['element'];
$sub_menu = '';
$mb_mainlink = '<li class="slflnk">' . l($element['#title'] . ' - ' . t('More'), $element['#href'], $element['#localized_options']) . '</li>';
@@ -79,6 +79,40 @@ function wetkit_bootstrap_menu_link__menu_block__main_menu(&$variables) {
/**
* Overrides theme_menu_tree().
*/
+ function wetkit_bootstrap_menu_link__menu_block__main_menu(&$variables) {
+ $element = $variables['element'];
+ $sub_menu = '';
+ $mb_mainlink = '<li class="slflnk">' . l($element['#title'] . ' - ' . t('More'), $element['#href'], $element['#localized_options']) . '</li>';
+ $depth = $element['#original_link']['depth'];
+
+ if ($element['#below']) {
+ if ((!empty($element['#original_link']['depth'])) && ($element['#original_link']['depth'] == 1)) {
+ // Add our own wrapper.
+ unset($element['#below']['#theme_wrappers']);
+ $sub_menu = '<ul class="sm list-unstyled" role="menu">' . drupal_render($element['#below']) . $mb_mainlink . '</ul>';
+ // Generate as standard dropdown.
+ $element['#attributes']['class'][] = 'dropdown';
+ $element['#localized_options']['html'] = TRUE;
+
+ // Set dropdown trigger element to # to prevent inadvertant page loading
+ // when a submenu link is clicked.
+ $element['#localized_options']['attributes']['data-target'] = '#';
+ $element['#localized_options']['attributes']['class'][] = 'item';
+ $element['#localized_options']['attributes']['data-toggle'] = 'dropdown';
+ }
+ }
+ // On primary navigation menu, class 'active' is not set on active menu item.
+ // @see https://drupal.org/node/1896674
+ if (($element['#href'] == $_GET['q'] || ($element['#href'] == '<front>' && drupal_is_front_page())) && (empty($element['#localized_options']['language']))) {
+ $element['#attributes']['class'][] = 'active';
+ }
+ $output = (in_array($element['#href'], array('<nolink>')) ? l($element['#title'], $element['#href'], $element['#localized_options']) : l($element['#title'], $element['#href'], $element['#localized_options']));
+ return '<li' . drupal_attributes($element['#attributes']) . '>' . $output . $sub_menu . "</li>\n";
+}
+
+/**
+ * Overrides theme_menu_tree().
+ */
function wetkit_bootstrap_menu_link__menu_block__mid_footer_menu(&$variables) {
global $counter;
global $needs_closing;
diff --git a/templates/menu/menu-tree.func.php b/templates/menu/menu-tree.func.php
index 8f85fa8..b00eaa3 100644
--- a/templates/menu/menu-tree.func.php
+++ b/templates/menu/menu-tree.func.php
@@ -14,6 +14,13 @@ function wetkit_bootstrap_menu_tree(&$variables) {
/**
* Overrides theme_menu_tree().
*/
+ function wetkit_bootstrap_menu_tree__menu_block__megamenu(&$variables) {
+ return '<ul role="menu">' . $variables['tree'] . '</ul>';
+}
+
+/**
+ * Overrides theme_menu_tree().
+ */
function wetkit_bootstrap_menu_tree__menu_block__main_menu(&$variables) {
return '<ul class="list-inline menu" role="menubar">' . $variables['tree'] . '</ul>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment