Skip to content

Instantly share code, notes, and snippets.

@mherchel
Created August 28, 2014 16:37
Show Gist options
  • Save mherchel/ba36d3979b392b1b51d7 to your computer and use it in GitHub Desktop.
Save mherchel/ba36d3979b392b1b51d7 to your computer and use it in GitHub Desktop.
Add level indicator css class to all menu items and menu links within Drupal theme
<?php
/*
* Add level indicator css class to all menu items and menu links.
*/
function THEME_menu_link(array $variables) {
$element = $variables['element'];
$sub_menu = '';
$element['#attributes']['class'][] = 'menu-item menu-item--level' . $element['#original_link']['depth'];
$menu_link = 'menu-item-link menu-item-link--level' . $element['#original_link']['depth'];
if ($element['#below']) {
$sub_menu = drupal_render($element['#below']);
}
$output = l($element['#title'], $element['#href'], array('attributes' => array('class' => array($menu_link))));
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