Hello developers and Drupal users,
I've come across an odd issue relating to Multi-lingual site configurations and this module in particular. Though it's output should be correct, for some strange reason, with the way my site is configured, the proper "path" link title and menu trail are not being selected.
Let me demonstrate via a dd() output.
In the case of my site, the following path https://achatsetventes.gc.ca/politiques-et-lignes-directrices/Archives-du-Guide-des-approvisonnements/Guide-des-approvisionnements-Version-2012-01 (don't go here, the url won't validate for you right now) when checking the _menu_trail_by_path_get_parent_candidates(drupal_get_path_alias()) we get the following return:
PARENT: Array
(
[0] => node/8310
[1] => node/8278
)
RECORD: Array
(
[menu_name] => navigation
[link_path] => node/8310
[link_title] => Supply Manual Archive
[depth] => 1
[mlid] => 2875
)
RECORD: Array
(
[menu_name] => navigation
[link_path] => node/8310
[link_title] => Archives du Guide des approvisonnements
[depth] => 1
[mlid] => 2880
)
What we see here, is in fact a doubling up of possibilities for the node/8310 menu trail. The problem is the breadcrumb is returning the following:
TPSGC >> achatsetventes.gc.ca >> Politiques et lignes directrices >> Supply Manual Archive >> Guide des approvisionnements : Version 2012-01
The problem here is the english "Supply Manual Archive" when it should actually read the french title "Archives du Guide des approvisonnements"
My thought is as follows:
Would it not be wiser to simply use the "language" option of the menu as opposed to trying to let the function _i18n_menu_link_title((array)$record, $language->language) do the trick? This seems to fail as it only takes the first option and ignores the second, meaningful choice?
I propose the following:
$results = db_select('menu_links','ml')
->fields('ml',array('menu_name','link_path','link_title','depth','mlid','language'))
->condition('link_path', $parent_candidates, 'IN')
->condition('language', $language->language, '=')
->execute();
and removing
// Get the Link Title if it can be found in a menu item
if ($record->link_title && !isset($matched_link_titles[$record->link_path])) {
$matched_link_titles[$record->link_path] = $record->link_title;
/*
if (module_exists('i18n_menu')) {
$matched_link_titles[$record->link_path] = _i18n_menu_link_title((array)$record, $language->language);
}
*/
}
We no longer need to test for the i18n module and we keep the mechanism simply at the db_select level.
If need be, I can roll up a patch. But, I'd like to get some thoughts on this first.
| Comment | File | Size | Author |
|---|---|---|---|
| #14 | 1861946-language-for-matched-menu-i18n-v2.patch | 1.51 KB | davy-r |
| #12 | 1861946-language-for-matched-menu-i18n.patch | 1.05 KB | davy-r |
| #4 | menu_trail_by_path-language-for-matched_menu-i18n.patch | 1.13 KB | jlenni |
Comments
Comment #1
berdirBoth are necessary.
The language condition when assigning a language to menu items, in the same way as i18n_menu is doing it:
This needs to be wrapped in a module exists('i18n_menu') because the language column only exists if that module is enabled.
The second part is still necessary, but only for menu items which have no or undefined language.
Comment #2
SeriousMatters commentedThe 'language' field in 'menu_links' table is provided by i18n_menu module (i18n_menu_schema_alter).
So we need to wrap if(module_exists('i18n_menu')) around the sql.
Comment #3
davy-r commentedHi wilco, could you supply a patch which includes #1?
Comment #4
jlenni commentedPatch to select only menus in the current language if i18n_menu is activated (assuming all candidate menus have a assigned language!)
Comment #5
jlenni commentedComment #6
davy-r commentedtriggering automated testing
Comment #7
davy-r commentedComment #12
davy-r commentedcreated new patch file
Comment #13
davy-r commentedComment #14
davy-r commentedThe above patch (by jlenni) didn't work in combination with entity_translation_i18n_menu, so I made a small modification.
Could someone test this new patch?
Comment #15
thamasTested manually using
- Title 7.x-1.0-alpha8
- Entity Translation, Entity Translation Menu 7.x-1.0-beta5
- Menu Trail By Path 7.x-2.1
Comment #17
davy-r commentedComment #18
davy-r commentedThis should now be fixed in 7.x-3.x-dev