My menu icons on a custom menu disappear after I edit the page associated to the menu item.

So the menu item text stays - its just the icon that vanishes into the ether.

I read about a problem with menu items disappearing when no translation exists for a page. But all my pages have translations and menu icons showing perfectly to begin with. It's just when I edit the page that the icon goes missing for that language.

It seems it could be to do with i18n module as I do not recall this problem until I set up my site as multilingual.

Using Menu Icons 6.x-2.4 and i18 6.x-1.5.

Help anyone?

CommentFileSizeAuthor
#2 menu_icons_953456_2.patch1014 bytesjtsnow
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

abudev’s picture

I found a simple solution, changing core modules/menu/menu.module:

function menu_nodeapi(&$node, $op) {

301 + if (isset($item['mlid'])) {
302 + $existing_item = db_fetch_array(db_query("SELECT * FROM {menu_links} WHERE mlid = %d", $item['mlid']));
303 + }
304 + $item['options']=unserialize($existing_item['options']);

jtsnow’s picture

Priority: Normal » Major
Status: Active » Needs review
FileSize
1014 bytes

I've attached a patch that fixes this problem. Unlike the fix in the previous comment, it does not involve hacking core. I patched against the latest dev version of the module. The problem is that the menu module clears the values in $form['menu']['options']. See menu_form_alter(). In order to preserve the menu icon settings, they need to be stashed somewhere else while the menu module does its thing. Then, just before the node is saved, we can insert the menu icon settings back into the node object.

bettibio’s picture

Version: 6.x-2.4 » 7.x-3.0-beta1

Same problem but do not seem related to the module menu. I removed all hook_node version 7 of menu.module:
hook_node_insert ()
hook_node_update ()
menu_node_save ($ node)
hook_node_delete ()
hook_node_prepare ()
menu_form_node_form_alter (& $ form, $ form_state)
menu_node_submit ($ node, $ form, $ form_state)
menu_form_node_type_form_alter (& $ form, $ form_state)
but the problem remains.
I'm using taxonomy menu to create menu items.

jenlampton’s picture

Title: Menu Icons disappear after editing page » Menu Icons disappear after editing node associated with menu item
Version: 7.x-3.0-beta1 » 6.x-2.4

I don't think that last comment had anything to do with this issue, so changing the version back. Please open a new issue if you having a problem with the D7 version, or you can test this patch if you hare having this problem on D6.

bettibio’s picture

I had opened an issue for d7 Menu Icons disappear after editing page, but was closed as a duplicate of this. Excuse my ignorance but what should I do to properly report the problem and have workarounds for?

acrollet’s picture

bettibio: the code is quite similar in both versions, so it's generally simplest to track things in one issue. Probably the best way to move the issue forward would be to post steps to reproduce the problem when using an otherwise vanilla (no other contrib modules installed) copy of Drupal. (7 is fine, since that's what you're working with)

zznq’s picture

Version: 6.x-2.4 » 7.x-3.x-dev

The issue as I saw it was that the module is modifying the options field in the menu_links table, which is a drupal core db table. It looks like whenever a node is altered, that has a relationship with the menu item, the menu_link record is updated and the options that this module is settings get overwritten. Perhaps Drupal core is being a bit too destructive.

My solution was to store the values in the menu_link table and somewhere else, in this case due to time I used variable_set. Maybe a menu_icon specific db would be better.

The real solution comes in by adding the menu_link_alter hook, this gets called whenever a menu_link gets saved. At this point I simply put the menu_icon values back into the menu_link options field. This seems to have fixed it for me.

Something like the following.

function menu_icons_menu_link_alter(&$item){
  $use_icon = variable_get('menu-icon-class-'.$item['mlid'].'-enable', false);
  if($use_icon) {
    
    $icon_path = variable_get('menu-icon-class-'.$item['mlid'].'-path', '');
    $icon_image_style = variable_get('menu-icon-class-'.$item['mlid'].'-image_style', '');
  
    $item['options']['menu_icon'] = array(
      'enable' => $use_icon,
      'path' => $icon_path,
      'image_style' => $icon_image_style,
    );
    
    if(!isset($item['options']['attributes']['class']))
      $item['options']['attributes']['class'] = array();
    
    $item['options']['attributes']['class'][] = "menu_icon";
    $item['options']['attributes']['class'][] = "menu-" . $item['mlid'];
  }
}
bettibio’s picture

In my case the problem is caused by the taxonomy menu module. Uninstalling the problem disappears.

acrollet’s picture

Version: 7.x-3.x-dev » 6.x-2.4

Since there is a patch against version 6 in this issue, I'm changing this issue back to version 6. I've re-opened #1437184: Menu Icons disappear after editing page for Drupal 7, please post exact steps to reproduce.

emilorol’s picture

Hi,

I posted a solution for Drupal 7 for this issue maybe something like that can be done for Drupal 6.

See it here: http://drupal.org/node/1437184#comment-5934980

Thank you,

Emil