Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Drupal | Omega | Transform the main menu into a select to be used into small screen sizes.
// see also https://gist.github.com/3201854
function mytheme_menu_tree__main_menu($variables) {
return '<select class="mobile-main-menu" onchange="location = this.options[this.selectedIndex].value;">'
. $variables['tree'] . '</select>';
}
function mytheme_menu_link__main_menu($variables) {
global $base_url;
$e = $variables['element'];
$attr = "";
if (isset($e['#localized_options']['attributes']['class'][0])
&& $e['#localized_options']['attributes']['class'][0] == "active-trail")
$attr = 'selected="selected"';
$link = $e['#href'] == "<front>" ? $base_url : $base_url . "/" . $e['#href'];
return '<option value="' . $link . '" ' . $attr . '>' . $e['#title'] . "</option>";
}
//main menu (level 2 sidebar) using the menu block module
function mytheme_menu_tree__menu_block__1(&$variables) {
return '<ul class="sidebar-menu">' . $variables['tree'] . '</ul>';
}
function mytheme_menu_link__menu_block__1($variables) {
$element = $variables['element'];
$sub_menu = '';
if ($element['#below']) {
$sub_menu = drupal_render($element['#below']);
}
$output = l($element['#title'], $element['#href'], $element['#localized_options']);
return '<li' . drupal_attributes($element['#attributes']) . '>' . $output . $sub_menu . "</li>\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.