I have a rule:
Name: node
Action with breadcrumbs: add parents
Action: leave
When I use this rule the breadcrumb prints parent items in the breadcrumb but that items aren't translated. Also their url's links to the untranslated menu item.
I search a little bit more and see that the function menu_hansel_get_parent in hansel.actions.inc doesn't support localization at all. The logic for geting menu item only works with unlocalized drupal. So I make a modification for that function and now it is working very well. Also it works with the domain module and multiple menus. I tested it on my live site.
Here is modified function:
/**
* Implements hook_hansel_get_parent().
*
* @param string $path
* @return array
*/
function menu_hansel_get_parent($path) {
global $language;
if (module_exists('menu')) {
$trail = menu_get_active_trail ();
$active_menu_item = array_pop($trail);
$active_menu_name = $active_menu_item["menu_name"];
// Try to get parent by menu.
$sql = 'SELECT p.link_path, p.link_title
FROM {menu_links} c
JOIN {menu_links} p ON c.plid = p.mlid
WHERE c.link_path = :path AND c.menu_name = :active_menu AND ( c.language = :current_language OR c.language = :default_language )
ORDER BY c.language ASC
LIMIT 1';
$res = db_query($sql, array(
':path' => $path,
':active_menu' => $active_menu_name,
':current_language' => $language->language,
':default_language' => "und",
));
if ($link = $res->fetchObject()) {
return array(
'path' => $link->link_path,
'title' => $link->link_title,
);
}
}
if (preg_match('/^node\\/([0-9]+)$/si', $path, $match)) {
// Try to get parent by nodetype settings.
$nodetypes = variable_get('hansel_nodetypes', array());
$node = node_load($match[1]);
if (($node = node_load($match[1])) && isset($nodetypes[$node->type])) {
return $nodetypes[$node->type];
}
}
return FALSE;
}
Can someone make a patch and testi it and commit it to dev so other can bedifit form this?
| Comment | File | Size | Author |
|---|---|---|---|
| #5 | 1786662-5-hansel-i18n.patch | 4.57 KB | mattew |
| #4 | 1786662-4-hansel-i18n.patch | 3.8 KB | mauritsl |
Comments
Comment #1
mauritsl commentedThanks for investigating this issue!
Multilanguage support is indeed weak in Hansel. There some other issues about this as well. I will try to find time soon to test all its features with i18n.
Comment #2
blackandcode commentedThanks for fast response. I also applied patch from http://drupal.org/node/1600700 for localized taxonomies. This patch also work good.
Comment #3
mattew commentedThis fix no longer works if the menu item is in Language Neutral and is localized (menu in "Translate and localize" mode) using i18n_string.
Here is a fix for that (pick the code above, and change the if ($link = $res->fetchObject()) {...} closure):
Tested and works for me.
Comment #4
mauritsl commentedIt breaks the site when i18n_menu is not enabled. And secondly, modified code doesn't follow the Drupal coding standards.
Patch attached should address this issues, but still needs some testing.
Comment #5
mattew commentedNew patch for the i18n fix :
To the maintainer: please, apply the patch, think about multilingual websites!
Comment #7
mauritsl commentedCommitted to GIT. Thanks!