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.

Comments

berdir’s picture

Both are necessary.

The language condition when assigning a language to menu items, in the same way as i18n_menu is doing it:

$query->condition('ml.language', array(LANGUAGE_NONE, i18n_language_interface()->language), 'IN');

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.

SeriousMatters’s picture

The '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.

davy-r’s picture

Status: Active » Postponed

Hi wilco, could you supply a patch which includes #1?

jlenni’s picture

Patch to select only menus in the current language if i18n_menu is activated (assuming all candidate menus have a assigned language!)

jlenni’s picture

Status: Postponed » Needs review
davy-r’s picture

Status: Needs review » Active

triggering automated testing

davy-r’s picture

Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, 4: menu_trail_by_path-language-for-matched_menu-i18n.patch, failed testing.

The last submitted patch, 4: menu_trail_by_path-language-for-matched_menu-i18n.patch, failed testing.

The last submitted patch, 4: menu_trail_by_path-language-for-matched_menu-i18n.patch, failed testing.

The last submitted patch, 4: menu_trail_by_path-language-for-matched_menu-i18n.patch, failed testing.

davy-r’s picture

Status: Needs work » Needs review
StatusFileSize
new1.05 KB

created new patch file

davy-r’s picture

Issue tags: +breadcrumb
davy-r’s picture

The 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?

thamas’s picture

Status: Needs review » Reviewed & tested by the community

Tested 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

  • davy-r committed a5e2b7e on 7.x-3.x
    Issue #1861946 by davy-r, jlenni, Berdir, wilco: This function...
davy-r’s picture

Version: 7.x-2.0 » 7.x-3.x-dev
davy-r’s picture

Status: Reviewed & tested by the community » Fixed

This should now be fixed in 7.x-3.x-dev

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.