Skip to content

Instantly share code, notes, and snippets.

@ThomasHambach
Created May 8, 2014 08:42
Show Gist options
  • Save ThomasHambach/f2dc09e112576128ef4e to your computer and use it in GitHub Desktop.
Save ThomasHambach/f2dc09e112576128ef4e to your computer and use it in GitHub Desktop.
Drupal 7, overwrite menu block tree
<?php
/**
* Implements hook_menu_block_tree_alter().
*/
function mymodule_menu_block_tree_alter(&$tree, &$config) {
global $language;
$default = language_default('language');
if($language->language != $default) {
$item = menu_link_load($config['parent_mlid']);
if($item['language'] != $language->language) {
// We want to show the correct language for our menu tree, what we will do next is not as pretty as we want
// it to be, but it will work. Get the translation of $item in $language->language and replace the current
// tree target with the children of the translation.
$result = db_select('menu_links', 'ml')
->fields('ml', array('mlid'))
->condition('i18n_tsid', $item['i18n_tsid'])
->condition('language', $language->language)
->execute()
->fetchAssoc();
if($result) {
$config['parent_mlid'] = $result['mlid'];
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment