In my module, I need to create sort of a menu block consisting of certain menu items collected from various menus, and flattened into one level.
I'm not sure about the correct chain of the Menu API functions to call. My first attempt was as follows:
function _MYMODULE_block_view(){
$html = '';
$menu_link = menu_link_get_preferred('node/287');
$html .= theme('menu_link', $menu_link);
dpm($menu_link);
return $html;
}
but it raises an error about several #attributes missing, so I guess this is not the right kind of object to get markup from. The API docs don't really help in understanding what kind of objects/parameters are returned/expected by functions, hence the question.
Edit:
Having given what Drupal complained about, the code now is as follows:
function _MYMODULE_block_view(){
global $language;
$langcode = $language->language;
$html = '';
$paths = array(
'node/287',
'node/3',
);
foreach($paths as $path){
$translations = i18n_get_path_translations($path);
if(!empty($translations[$langcode])){
$i18n_path = $translations[$langcode]['href'];
$menu_link = menu_link_get_preferred($i18n_path);
$link = array(
'#theme' => 'link',
'#text' => $menu_link['link_title'],
'#path' => $path,
'#options' => array('attributes' => array('title' => $menu_link['link_title'])),
'#below' => NULL,
'#title' => $menu_link['link_title'],
'#href' => $path,
'#attributes' => array(),
'#localized_options' => array(),
'#prefix' => '<li>',
'#suffix' => '</li>'
);
$html .= theme('menu_link', array('element' => $link));
}
}
return "<ul>$html</ul>";
}
It does not spit out errors but... should I really trust it?