Skip to content

Instantly share code, notes, and snippets.

@knibals
Forked from henrijs/gist:6225177
Last active August 29, 2015 14:01
Show Gist options
  • Save knibals/ba92294127400fcad367 to your computer and use it in GitHub Desktop.
Save knibals/ba92294127400fcad367 to your computer and use it in GitHub Desktop.
Ajouter une classe du niveau du menu dans l'UL pour theming
```php
function themename_menu_link(&$vars) {
$element = $vars['element'];
$sub_menu = '';
$element['#attributes']['data-menu-parent'] = array($element['#original_link']['menu_name'] . '-' . $element['#original_link']['depth']);
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";
}
function themename_preprocess_menu_tree(&$vars) {
$tree = new DOMDocument();
@$tree->loadHTML($vars['tree']);
$links = $tree->getElementsByTagname('li');
$parent = '';
foreach ($links as $link) {
$parent = $link->getAttribute('data-menu-parent');
break;
}
$vars['menu_parent'] = $parent;
}
function themename_menu_tree(&$vars) {
return '<ul class="menu ' . $vars['menu_parent'] . '">' . $vars['tree'] . '</ul>';
}
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment