The following scenario reproduces the problem:

  • Install plain vanilla Drupal 7.12
  • Add a new menu to the website (e.g. "Test menu")
  • Set "Source for the main links" to your newly created menu (/admin/structure/menu/settings)
  • Add some menu items to the new menu (nest a few of them)

Navigate through the newly created menu items. everything works OK till here, the active menu trail follows your path through the website.

  • Now, install the i18n modules (don't forget the i18n_menu module)
  • Now navigate through your menu items again, you'll notice that the active trail is broken (this also explaines the weird behaviour of the menu_block module

Problem lies within the fact that the menu_update_7003() hook in Drupal 7.12 isn't executed when you install Drupal 7.12, only when an update of Drupal core is performed! Try set the "schema_version" field of the menu module in the system table to "7002" and execute update.php. Problem Solved! The actual patch in menu_update_7003() is executed and everything works as it should.

Should this problem be fixed in Drupal core?

Comments

catch’s picture

Project: Drupal core » Internationalization
Version: 7.12 » 7.x-1.x-dev
Component: menu system » Menus

Moving this to i18n.

gsquirrel’s picture

I tried changing schema and running update (again) but does not solve it for me - the same items still fail to show secondary menu block.

tempo22’s picture

Thanks a lot for this post,

i was getting headache trying to figure out why the same site features wasn't working on my fresh install and my old but up to date site.

vegardjo’s picture

excellent! worked for me :)

fretje’s picture

Why has this been changed to i18n? This is about the core menu module...

mgifford’s picture

@vegardjo - what worked for you? I don't see a patch.

Did you just manually force this:

/**
 * Add missing custom menus to active menus list.
 */
function menu_update_7003(&$sandbox) {
  // Make sure all custom menus are present in the active menus variable so that
  // their items may appear in the active trail.
  // @see menu_set_active_menu_names()
  $active_menus = variable_get('menu_default_active_menus', array_keys(menu_list_system_menus()));
  $update_variable = FALSE;
  foreach (menu_get_names() as $menu_name) {
    if (!in_array($menu_name, $active_menus) && (strpos($menu_name, 'menu-') === 0)) {
      $active_menus[] = $menu_name;
      $update_variable = TRUE;
    }
  }
  if ($update_variable) {
    variable_set('menu_default_active_menus', $active_menus);
  }
  // Clear the menu cache.
  cache_clear_all(NULL, 'cache_menu');
}

@catch - why isn't this a Core issue if menu_update_7003() is missed?

catch’s picture

The bug only exists when i18n_menu is installed, see the OP.

menu_update_7003() is an update, so should not ever run on a new install.

The fact that running menu_update_7003() makes i18n_menu work, does not mean that this is a core bug - it might be a core bug, but in that case steps to reproduce that involve core only should be possible, or it may be there is a core bug that i18n_menu exposes, but we won't know that without more information.

rypit’s picture

Please see: #1351678: Follow menu_link_get_preferred active trail handling for custom menus
http://drupal.org/node/1351678#comment-5582922
Running the following versions and this problem seems resolved:

  • Drupal 7.12
  • Multilingual - Internationalization (i18n) 7.x-1.4
  • Menu Block (menu_block) 7.x-2.3
mgifford’s picture

Are you seeing [in_active_trail] elements in the array as I tried to describe here:
http://drupal.org/node/1425342#comment-5667366

I tried your suggestion and it didn't work for me.

I'm using the config you're suggesting and am clearing cache & doing update.php

vegardjo’s picture

@mgifford, yes - I changed the "schema_version" field of the menu module the database to "7002" and executed update.php

mgifford’s picture

Issue tags: +menu, +active menu

Ok, so you just did something like:

UPDATE `drupal`.`system` SET `schema_version` = '7002' WHERE CONVERT( `system`.`filename` USING utf8 ) = 'modules/menu/menu.module' LIMIT 1 ;

I update it:

$ drush updb -y
No database updates required [success]
Finished performing updates. [ok]

Should I see any other changes?

laiska’s picture

Thanks for this tip, it solved this issue for me when upgrading to D7.12 from D6.25.

vollepeer’s picture

@catch
Aren't updates to modules improvements or bug fixes? Shouldn't these updates be executed on new installs of the module too?

Jose Reyero’s picture

Priority: Major » Normal
Status: Active » Postponed (maintainer needs more info)

Though @catch is right, this is pretty weird.

Could anyone post the content of the variable 'menu_default_active_menus' before and after the update?

vollepeer’s picture

Before running the update, this variable does not exists in the database. It gets created when performing the update.

Jose Reyero’s picture

I mean when installing a new site using latest Core. As mentioned in #7, running the update on a new clean site fixes the issue.

Since the update creates the variable, shouldn't a clean Drupal install create it?

Madis’s picture

I'm not sure when/where the 'menu_default_active_menus' variable should be added, but currently it does not get created with a standard Drupal 7.12 installation.

In case this is helpful here's a test case I tried:

1) Standard Drupal 7.12 install.
2) Created a custom menu.
3) Created 2 pages, added them to the custom menu in a parent-child relationship. Placed the menu block in a sidebar. At this stage the 'menu_default_active_menus' variable doesn't exist, but the menu displays as expected.
4) Installed menu translation (using the latest i18n and variable dev versions) -> the variable still doesn't exist, but the menu is now broken.
5) Executed code in menu_update_7003() function -> the variable gets created and the menu now displays as expected again.

Jose Reyero’s picture

Some notes, looking at Drupal core code:

1. When coming from a clean install, the variable is not set, but it defaults to array('navigation', 'management', 'user-menu', 'main-menu'), coming from: array_keys(menu_list_system_menus());

2. Then every time a new menu is saved through menu_save(), it gets added to the variable. The menu name doesn't matter.

3. When running the update hook, the value is set to the previous array + any other custom menu that has been created (only if such custom menus exist, we check for 'menu-' in the menu name).

So I think the values may be different when creating menus with other modules whose name doesn't start with 'menu-'. Maybe features? Maybe others?

miiimooo’s picture

@Jose: yes I can confirm. I have a menu block using the book module (which has a weird half menu / half not way of doing things) and I'm seeing exactly the same issue (using Drupal 7.12, i18n 7.x-1.5, menu_block 7.x-2.3)
Any ideas what to do?

miiimooo’s picture

Just to prove your point I have added this piece of code:

function custom_mymodule_init() {
  // hack
  $menus = variable_get('menu_default_active_menus');
  if (!in_array('book-toc-5139', $menus)) {
    $menus[] = 'book-toc-5139';
    variable_set('menu_default_active_menus', $menus);
  }
}

and the problem is solved.

Jose Reyero’s picture

Title: Active menu trail breaks » Active menu trail breaks (menu_update_7003 creates inconsistencies).
Project: Internationalization » Drupal core
Version: 7.x-1.x-dev » 7.x-dev
Component: Menus » menu system
Status: Postponed (maintainer needs more info) » Active

As explained in #18, the value of the variable is different with and without running the update.

1. If running the update, it 'forgets' all menus that don't start with 'menu-'.
2. If installed the version from scratch, it adds all the menus to the variable as they are being created.

So back to Drupal core. That update should be cleaned up (I don't know which of the two behaviors is the right one).

Jose Reyero’s picture

Issue summary: View changes

Update