Hi,
in my recent project I'm using Taxonomy Menu module as well as Menu Icons. Unfortunately Taxonomy Menu interferes the other module, so that after updating a term, the menu icon setting gets overwritten.

So I was implementing hook_taxonomy_menu_update() in order to set the 'options' attribute of the menu link with the existing data (containing the icon configuration). So long, so good. But when I tested this functionality I've seen that the settings are still overridden.

Why? Because in the _taxonomy_menu_save() function you are setting the 'options' property of the link from ground up, instead of checking if the parameter has already set some options and use them, if present.

You should do something like that before defining the $link array:

  $options = isset($item['options']) ? $item['options'] : array();
  if (!isset($options['attributes'])) {
    $options['attributes'] = array();
  }
  $options['attributes']['title'] = trim($item['description']) ? $item['description'] : $item['name'];

and set this $options array in the $link array instead.

I'm sorry to not proposing a patch here, but I'm a git n00b. I've done it once successfully, but failed creating one (with Aptana) a few days ago and don't know why... I guess I'd need some time to figure out again, what I've done wrong, but I don't have this time now...

Comments

whimsy’s picture

Version: 7.x-1.x-dev » 6.x-2.9
Category: feature » bug

I am having this same issue in version 6. In the Menu settings, I changed the Menu Link Title as it is different then the taxonomy term. Whenever I add or modify a node, my Menu Link Title is wiped out and reset to the taxonomy term by Taxonomy Menu. I can get around this by unchecking the Synchronise changes to this vocabulary option in the Taxonomy Menu settings but this causes other issues.

acrollet’s picture

Version: 6.x-2.9 » 7.x-2.x-dev

Hi there,

I'm the 7.x maintainer of the menu_icons module, and I can confirm that taxonomy_menu is incompatible with menu_icons. (and any other module that saves data in the menu link options) It would be wonderful if taxonomy_menu could be re-worked to change this behavior.

hles’s picture

I don't think it would happen in 7.x-2.x, someone up to confirm that ? Would be great !

hles’s picture

Status: Active » Postponed (maintainer needs more info)
hles’s picture

Status: Postponed (maintainer needs more info) » Closed (fixed)
hles’s picture

Issue summary: View changes

corrected typo error: $options array need to be used in $link, not in $item

zmove’s picture

Status: Closed (fixed) » Active

I reopen the issue because there is the same problem with Icon api and Menu icon submodule.

To reproduce :

  • Create a new taxonomy, synchronize it with a menu thanks to taxonomy_menu
  • Edit one of the menu item you just created, add an icon with icon api
  • Edit your taxonomy term to trigger the menu rebuild
  • See your taxonomy term, the icon just disappears

I don't think it need another issue as the title of this one perfectly describe the problem. Just put it active again :/

oxyc’s picture

For reference, this is how I solved it with a hook.

/**
 * Implements hook_menu_link_alter().
 *
 * Preserve the menu item options during taxonomy_menu synchronizations.
 */
function custom_menu_link_alter(&$item) {
  // Only act on menu links saved by taxonomy_menu.
  if (empty($item['module']) || $item['module'] != 'taxonomy_menu') {
    return;
  }

  if (!empty($item['mlid']) && $existing = menu_link_load($item['mlid'])) {
    $new_options = $item['options'];
    $existing_options = $existing['options'];
    $item['options'] = drupal_array_merge_deep($existing_options, $new_options);
  }
}
zmove’s picture

The code above doesn't work for me. When I make some change in my taxonomy, my menu icons provided by icon api still disappears.

init90’s picture

One more related example:

/**
 * Implements HOOK_menu_link_alter().
 */
function gm_custom_menu_link_alter(&$item) {
  // Only act on menu links saved by taxonomy_menu.
  if (empty($item['module']) || $item['module'] !== 'taxonomy_menu') {
    return;
  }

  // Do nothing if menu item is new.
  if (empty($item['mlid'])) {
    return;
  }

  $existing_item = menu_link_load($item['mlid']);

  // Do nothing if menu item don't have parent.
  if (empty($existing_item['plid'])) {
    return;
  }

  $parent_item = menu_link_load($existing_item['plid']);

  // Do nothing if parent menu item is not semantic.
  if ($parent_item['link_path'] !== '<nolink>') {
    return;
  }

  // In case when menu item generated by 'taxonomy_menu' module was manually
  // moved under 'semantic' menu item then we try to keep the structure
  // when the item is updated from the taxonomy side.
  //
  // In order to it we inherit from existing item properties related to the
  // hierarchy, depth and weight.
  $item['plid'] = $existing_item['plid'];
  $item['weight'] = $existing_item['weight'];
  $item['link_weight'] = $existing_item['link_weight'];
  $item['depth'] = $existing_item['depth'];
  $item['p1'] = $existing_item['p1'];
  $item['p2'] = $existing_item['p2'];
  $item['p3'] = $existing_item['p3'];
  $item['p4'] = $existing_item['p4'];
  $item['p5'] = $existing_item['p5'];
  $item['p6'] = $existing_item['p6'];
  $item['p7'] = $existing_item['p7'];
  $item['p8'] = $existing_item['p8'];
  $item['p9'] = $existing_item['p9'];
}

vladimiraus’s picture

Status: Active » Closed (outdated)

Thank you for your contributions.
Drupal 7 is no longer supported.
Closing this issue as outdated.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.