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:
before
and $variables['items'] after the if:
After

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

Yonka created an issue. See original summary.

yoa’s picture

Issue summary: View changes
Status: Active » Needs review
StatusFileSize
new713 bytes
yoa’s picture

Issue summary: View changes
StatusFileSize
new768 bytes
avpaderno’s picture

henry tran’s picture

StatusFileSize
new788 bytes

Fix child menu items lost.

chop’s picture

We 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.

chop’s picture

We 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.

chop’s picture

Status: Needs review » Needs work

matthieuscarset’s picture

Status: Needs work » Needs review

Thank you for this issue and for testing it.

I have committed a change to try not to loose information because of the preprocess function.

  • matthieuscarset committed a30d6bf on 2.0.x
    Fix menu parameters with preprocess $variables[items] only #3133909...
matthieuscarset’s picture

Status: Needs review » Fixed

Closing issue to clean the list.

Feel free to reopen it if you can reproduce the issue with the latest release 3.0.0.

matthieuscarset’s picture

Status: Fixed » Closed (fixed)