Menu for 'currently used language' should be used, otherwise one cannot control what language will be set in breadcrumbs.
CASE:
- two enabled languages: default (EN), and non-default (non-EN)
- two menus for nodes: first set for default language (EN), second set for non-default language (non-EN)
- menu breadcrumb configured to use both above menus
PROBLEM:
- menu breadcrumb will use first found menu no matter what language is set
RESULT (Invalid):
- people displaying page in non-default language (non-EN) will see default language (EN) breadcrumbs
- changing menus' order in 'menu breadcrumb' will cause reversed situation: people displaying page in default language (EN) will see non-default (non-EN) breadcrumbs
My temporary solution:
public function applies(RouteMatchInterface $route_match) {
//...//
foreach ($menus as $menu_name => $params) {
// Look for current path on any enabled menu.
if (!empty($params['enabled'])) {
// --- tmp fix below --- //
$menuObj = \Drupal::entityTypeManager()
->getStorage('menu')
->loadByProperties([ 'id' => $menu_name,]);
if ($menuObj) {
$menuItem = reset($menuObj);
}
$menuLangId = $menuItem->language()->getId();
$currentLanguage = \Drupal::languageManager()->getCurrentLanguage()->getId();
if ($menuLangId != $currentLanguage) {
continue;
}
// --- end tmp fix --- //
$trail_ids = $this->menuActiveTrail->getActiveTrailIds($menu_name);
//...///
}
}
}
Comment | File | Size | Author |
---|---|---|---|
#4 | 2865800-menu-match-language.patch | 2.65 KB | rphair |
Comments
Comment #2
rphair CreditAttribution: rphair at COSD commentedthanks @pawel_r, this was reported earlier in https://www.drupal.org/node/2840178 but I wasn't sure how to deal with it at the time. The logic above looks straightforward enough, except that your code uses the current interface language, though issues since then (2827786, 2855692) confirm that it should match the current content language.
I'm pretty sure that menu language comparison will also disqualify "taxonomy attachment" for the same menu in the code that follows. Just need to test this code is the best way of doing it, please stand by....
Comment #3
rphair CreditAttribution: rphair at COSD commentedoops...
Comment #4
rphair CreditAttribution: rphair at COSD commentedComment #5
rphair CreditAttribution: rphair at COSD commentedpatch relative to dev version, also checking it into dev now. Note that logic is changed a bit... please let me know how it's working in this case, if all OK will bring into new version 1.1 (comments about this welcome).
Comment #7
pawel_r CreditAttribution: pawel_r as a volunteer commentedI've tried DEV and it's working fine.
Logic is the same, yours code is nicer (when doing such 'fixes' I do prefer having just one place in code, it's easier to managed during updates etc. )
Comment #8
rphair CreditAttribution: rphair at COSD commentedthanks for testing @pawel_r: marked current dev as version 8.x-1.1.
Comment #9
pawel_r CreditAttribution: pawel_r as a volunteer commentedthx!
Comment #10
weri CreditAttribution: weri at Previon Plus AG commentedI have to reopen this issue, because it does not work correctly with translated menus.
We have a menu defined as German (DE) for the default language and do translate the menu and menu items to French (FR). In this case we only have the correct breadcrumbs on the German page, but not on the French, because the main menu is filtered out in this case.
I think we can not do
for all cases. Especially when only one menu is used for multiple languages.
I think there is not an easy solution to implement that generic for all situations, but It's possible to allow an additional configuration like "We have a menu per language" or so.
What did you mean?
Currently I switched back to version 8.1.0.
Comment #11
rphair CreditAttribution: rphair commentedOK, what about implementing a third checkbox for each menu, about whether to implement this patched code? We'd have to answer these questions first:
Comment #12
weri CreditAttribution: weri at Previon Plus AG commentedImplementing a third checkbox for each menu sounds good and straightforward.
Comment #13
rphair CreditAttribution: rphair commentedAgreed, have opened up another issue to track this as a feature request (https://www.drupal.org/node/2880451). Was hoping to push some code for this out to dev tonight but missed my window, please stay tuned & will have something there for you to test soon....
Comment #14
rphair CreditAttribution: rphair commenteddear followers of this issue, please try this patch (https://www.drupal.org/node/2880451#comment-12105533), now also in the dev version, to be sure it accommodates both preferences. As soon as this is confirmed by the community I would like release this as version 1.2 to reconcile the two use cases above & allow everyone to upgrade to the same version.
Comment #15
rphair CreditAttribution: rphair at COSD commentedConfirmed working by user community: https://www.drupal.org/node/2883391#comment-12115404 ...
Pushing out the dev version that reconciles this issue as 8.x-1.2.