In function menu_manipulator_preprocess_menu the filtering of languages is applied this way:
if ($do_filter) {
$menu_tree_translated = menu_manipulator_get_multilingual_menu($variables['menu_name']);
$variables['items'] = isset($menu_tree_translated['#items']) ? $menu_tree_translated['#items'] : [];
}
but this causes information loss.
if i print my $variables['items'] before and after this if ($do_filter) its very obvious.
(in the following images i printed from a menu that is using also menu_item_extras.)
$variables['items'] before the if:

and $variables['items'] after the if:

to fix it i used my theme hook:
// Implements theme_preprocess_menu().
function MYTHEMEpreprocess_menu(&$variables, $hook){
$menu_name = 'my-menu-name';
$moduleHandler = \Drupal::service('module_handler');
if (isset($variables['menu_name']) && $menu_name == $variables['menu_name']) {
if ($moduleHandler->moduleExists('menu_manipulator')) {
$menu_tree_translated = menu_manipulator_get_multilingual_menu($menu_name);
if (isset($menu_tree_translated['#items'])) {
$variables['items'] = array_intersect_key($variables['items'], $menu_tree_translated['#items']);
} else {
$variables['items'] = [];
}
}
}
}
perhaps the intercetion should be implemented in menu_manipulator_preprocess_menu
I added a naively implemented patch.
Comments
Comment #2
yoaComment #3
yoaComment #4
avpadernoComment #5
henry tran commentedFix child menu items lost.
Comment #6
chop commentedWe have a custom "Child Menu" block module that will output all the menu children of a current page in a block. When installing Menu Manipulator our Child Menu block breaks as the menu tree items returned was always empty.
The patch in #3133909-5: preprocess_menu causes information loss when multilingual option is enabled submitted by @tvhung fixes this issue fo us.
Comment #7
chop commentedWe had to revert the patch from #3133909-5: preprocess_menu causes information loss when multilingual option is enabled as it stopped the removal all untranslated menu items. It essentially didn't work.
In the end we've had to use this #2466553-75: Untranslated menu items are displayed in menus instead of this module to resolve the issue.
Comment #8
chop commentedComment #10
matthieuscarset commentedThank you for this issue and for testing it.
I have committed a change to try not to loose information because of the preprocess function.
Comment #12
matthieuscarset commentedClosing issue to clean the list.
Feel free to reopen it if you can reproduce the issue with the latest release
3.0.0.Comment #13
matthieuscarset commented