Download & Extend

Menu is not created from 'Menu settings'

Project:Internationalization
Version:5.x-2.1
Component:User interface
Category:bug report
Priority:normal
Assigned:Unassigned
Status:closed (fixed)

Issue Summary

Hi.
I have some problems with menu and i18n module. I read the module documentation, but I haven't found the answers I was looking for.

1) It seems that with i18n installed and activated, if I create a new content (e.g. a page) and create a contextual menu item (i.e. I create a menu item from the "Menu settings" section at the bottom of the page), the menu item isn't displayed at all, nor in the menu itself, nor in "Administer -> Site Building -> Menus" page. My only chance is to edit the page I created, open again the "Menu settings" section and click on "You may also edit the advanced settings for this menu item", then click on "Submit" on the next page. In this way the menu item is shown.
Is this behaviour correct? Or is it a bug?

2) And, by the way, is there a way to create a unique menu item that point to right content depending on language? I mean, is there a way to create a single menu with items that points to english version of pages, but if my language is italian all the items point to corresponding node translations? I'd like to avoid creating 2 identical menu, one for english and one for italian. I'd like to have one menu only used in both language.

Any help will be appreciated.
Tiziano

Comments

#1

Title:Contextual menu creation» Nobody?

No one can help me?

#2

Title:Nobody?» Contextual menu creation

#3

Title:Contextual menu creation» Menu is not created from 'Menu settings'
Version:5.x-1.x-dev» 5.x-2.0
Category:support request» bug report

I can confirm this behavior on Drupal 5.1 and would certainly consider it to be a bug. Before installing i18n everything works as expected in regards to menu creation. After installing i18n menus are not created any more when adding new content.

1) It seems that with i18n installed and activated, if I create a new content (e.g. a page) and create a contextual menu item (i.e. I create a menu item from the "Menu settings" section at the bottom of the page), the menu item isn't displayed at all, nor in the menu itself, nor in "Administer -> Site Building -> Menus" page.

The described workaround works fine:

My only chance is to edit the page I created, open again the "Menu settings" section and click on "You may also edit the advanced settings for this menu item", then click on "Submit" on the next page. In this way the menu item is shown.
Is this behaviour correct? Or is it a bug?

#4

I have exactly the same problem. D5.1, i18n 5.x-2.0; I am switching back to the older i18n version...

#5

Version:5.x-2.0» 5.x-1.x-dev
Status:active» fixed

I think I have fixed the menu issues in latest drupal-5. Please, try

#6

Status:fixed» closed (fixed)

#7

Version:5.x-1.x-dev» 5.x-2.1
Status:closed (fixed)» active

Hi. Sorry for the big delay, but I've been very very busy.
I tried version 5.x-2.1 of i18n module, but the problem is still there.
I looked into the code and I found that this behaviour is due to the value of 'type' field assigned to menu item. I don't know well how menu system works, but, creating some menu items from 'Menu settings', I noticed that:

- without i18n: the 'type' field equals to 0x76 (decimal 118) and menu item is displayed
- with i18n: the 'type' field equals to 0x56 (decimal 86) and menu item is not displayed

The difference between the two values is 0x20 (decimal 32) that corresponds with flag MENU_MODIFIED_BY_ADMIN.
I also noticed that when a new menu item is created from menu.module, the following instruction is executed (in menu_edit_item_save function):

$edit['type'] = $edit['type'] | MENU_MODIFIED_BY_ADMIN;

So, I tried to add a similar instruction in i18n.module (in i18n_nodeapi) like this:

...
if (isset($node->menu) && !$node->menu['delete'] && $node->menu['title']) {
  $item = $node->menu;
  $item['path'] = ($item['path']) ? $item['path'] : "node/$node->nid";
  $item['type'] = $item['type'] | MENU_MODIFIED_BY_ADMIN;
  if ($item['mid']) {
    // Update menu item
    db_query("UPDATE {menu} SET pid = %d, path = '%s', title = '%s', description = '%s', weight = %d, type = %d, language = '%s' WHERE mid = %d", $item['pid'], $item['path'], $item['title'], $item['description'], $item['weight'], $item['type'], $item['mid'], $node->language);
    drupal_set_message(t('The menu item %title has been updated with node language.', array('%title' => $item['title'])));
  } elseif(SAVED_NEW == menu_save_item($item)) {
    // Creating new menu item with node language
    db_query("UPDATE {menu} SET language = '%s' WHERE mid = %d", $node->language, $item['mid']);
    drupal_set_message(t('The menu item %title has been added with node language.',  array('%title' => $item['title'])));        
  }
  menu_rebuild();
  unset($node->menu); // Avoid further processing by menu module
}
...

Now menu item creation seems to work well, but I don't have time to test it (and I don't know if it's right, since, as I told, I don't know menu system very much).
Tell me what do you think about it.

Thank you.
Tiziano

#8

Thank you, Tiziano, for the suggestion. It really solves the problem!

I am wondering if the particular type value has something to do with user permissions.

#9

Status:active» fixed

Fixed, thanks

#10

Status:fixed» closed (fixed)

#11

It might be helpfull to note that the fix is *not* available in the 5.x-2.1 version, only in the development branch.

#12

Status:closed (fixed)» needs review

I found an another promplem. When I modify a menu under /node/edit/* the menu did not change.

/**
* Implementation of hook_nodeapi().
*/
function i18n_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
  if (variable_get("i18n_node_$node->type", 0)) {
      switch ($op) {
      case 'load':
        return db_fetch_array(db_query("SELECT trid, language, status AS i18n_status FROM {i18n_node} WHERE nid=%d", $node->nid));
      case 'insert':
      case 'update':
        db_query("DELETE FROM {i18n_node} WHERE nid=%d",$node->nid);
        if($node->language){
          // Assign a trid from the beginning
          db_query("INSERT INTO {i18n_node} (nid, trid, language, status) VALUES(%d, '%d', '%s', '%d')", $node->nid, $node->trid, $node->language, $node->i18n_status);
        }
        // Handle menu items. Fixes duplication issue and language for menu items which happens when editing nodes in languages other than current.
        if (isset($node->menu) && !$node->menu['delete'] && $node->menu['title']) {
          $item = $node->menu;
          $item['path'] = ($item['path']) ? $item['path'] : "node/$node->nid";
    $item['type'] = $item['type'] | MENU_MODIFIED_BY_ADMIN;

          if ($item['mid']) {
            // Update menu item
            <b>db_query("UPDATE {menu} SET pid = %d, path = '%s', title = '%s', description = '%s', weight = %d, type = %d, language = '%s' WHERE mid = %d", $item['pid'], $item['path'], $item['title'], $item['description'], $item['weight'], $item['type'], $item['mid'], $node->language);</b>
            drupal_set_message(t('The menu item %title has been updated with node language.', array('%title' => $item['title'])));
          } elseif(SAVED_NEW == menu_save_item($item)) {
            // Creating new menu item with node language
            db_query("UPDATE {menu} SET language = '%s' WHERE mid = %d", $node->language, $item['mid']);
            drupal_set_message(t('The menu item %title has been added with node language.',  array('%title' => $item['title'])));
          }
          menu_rebuild();
          unset($node->menu); // Avoid further processing by menu module
        }
        break;
      case 'delete':
        db_query('DELETE FROM {i18n_node} WHERE nid=%d', $node->nid);
        break;
      }
  }
}

In that function there is a bug. The $item['mid'] and the $node->language variables are inverted in menu update query.

This is the correct order.

db_query("UPDATE {menu} SET pid = %d, path = '%s', title = '%s', description = '%s', weight = %d, type = %d, language = '%s' WHERE mid = %d", $item['pid'], $item['path'], $item['title'], $item['description'], $item['weight'], $item['type'], $node->language, $item['mid']);

#13

Status:needs review» fixed

Just two notes:
- Of course the fix is not in 5.x-2.1 version, it is in the dev branch, which will soon be 5.x-2.2. That's why we have tagged versions for.
- Abt latest comment, please if you find another problem, open another issue.

#14

Really thank you for the fixes in this thread. Now I only have one problem left with i18n and menus. Is it possible that a missing MENU_MODIFIED_BY_ADMIN is also causing the problem I´ve described in another issue?

http://drupal.org/node/187785

Greats from Germany
LeisureLarry

#15

Status:fixed» closed (fixed)

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