Using this module I've found something odd. When I move terms around (change their parents) it usually works fine and the taxonomy menu reflect those changes except on one case:

Steps to reproduce:

1) Create a term (let's call it Term A) that has no parent (top level term). The menu now has a top level entry.
2) Assign a parent (Term B) to that term, that is, make the term the child of Term B.

After step (2) the Term A should appear as a child of the Term B in the menu:

- Term B
-- Term A

but it keeps coming as:

- Term B
- Term A

no matter what I do. Things I've tried that haven't worked:

-Saving Term A or Term B again.
-Moving Term A around, try to make it the child of another term.
-Rebuilding cache.
-Saving the taxonomy menu again (hoping that maybe it would rebuild the entire menu).

The only thing that has worked for me has been deleting the term and creating it again with the right parent. However that is not a solution in my case (I have a lot of content categorized with the offending term).

Is this the expected beahviour of the module or a bug?

Comments

millenc created an issue. See original summary.

dkre’s picture

I can confirm this with Drupal 8.3.0 ~ Taxonomy Menu 8.3.3

Cache rebuild + cron have no effect

millenc’s picture

I've managed to get it working by setting the option "All menus entries are expanded" and setting the depth to 9 (my taxonomy tree has 5-6 levels at most). With this configuration the module generates a menu with the whole taxonomy tree structure and moving a parent term below another term have the desired effect that the generated menu gets updated (the term appears below it's correct parent).

Maybe it's just the way the module works, if the whole tree is not available in the menu, moving a parent term does not work as it's parent does not really exist.

@dkre,

Try setting the configuration that I mention in this comment to see it that fixes your issue.

jeremyH1024’s picture

Drupal: 8.3.2
Taxonomy Menu: 8.x-3.3

Millenc: Your fix works, but appears to be temporary. I added a new article and the taxonomy went back to the previous broken state.
I changed the settings after it broke and it repaired the issue again.

millenc’s picture

@jeremyH1024

That's weird then. Anyhow, my fix was intended to be a workaround rather than a proper solution to the problem. I guess there's certainly a bug involved, so let's keep this issue open and see if someone more knowlegdeable about the module can give a definitive answer.

gaurav.kapoor’s picture

I wasn't able to reproduce this issue. I didn't face any such problem , when i created taxonomy term , added it as parent for other previously built terms , cleared the cache , menu changed accordingly.

Utilvideo’s picture

Same bug.

Utilvideo’s picture

Solve problem.

https://www.drupal.org/node/2762037

But after cache clear, not working:(

Utilvideo’s picture

Applay patch from here

https://www.drupal.org/node/2830188

and drag and drop in menu, not in taxonomy, and it worked.

but if order taxonomy menu, is change menu weight and order (with this patch https://www.drupal.org/node/2762037), but after cache clear back again.

I think that problem in multilanguage sites.

Giovanni Canzio’s picture

Same issue here... any news?

DamienMcKenna’s picture

I just tested and the changes made to the current 8.x-3.x codebase don't resolve this problem either.

Anybody’s picture

I can also confirm #11.
When creating a term on root level first and then moving it into a deeper level > max depth, the menu item is not being deleted.

Vojta’s picture

Tichris59’s picture

I have the same problem with drupal 8.6.3 and last stable release of this menu ( 8.x-3.3 ).

When I add a term, delete a term : no cache problem
When I move a term to another parent : cache problem, I need to rebuild router.

I did a workaround in a custom module, it's an easy hook waiting the fix in the module :

/**
 * Implements hook_entity_type_update().
 */

function  mymodule_custom_taxonomy_term_update( Drupal\Core\Entity\EntityInterface $entity )
{
  //here hierarchy is the vocabulary name used with taxonomy menu
    if( "hierarchy" == $entity->bundle() ){
        \Drupal::service('router.builder')->rebuild();
}
batkor’s picture

I think that implementing a menu deriver is redundant.

pookmish’s picture

The suggestion in #14 didn't seem to work for my scenario. I took a more extreme approach that deletes the menu item when updating the term. Then the taxonomy menu module will rebuild that menu link if necessary.

/**
 * Implements hook_entity_type_update().
 */
function mymodule_taxonomy_term_update(TermInterface $entity) {
  $original_parent = $entity->original->get('parent')->getString();
  if ($original_parent == $entity->get('parent')->getString()) {
    return;
  }
  $database = \Drupal::database();
  $menu_link_exists = $database->select('menu_tree', 'm')->fields('m')
    ->condition('id', 'taxonomy_menu.menu_link%', 'LIKE')
    ->condition('route_param_key', 'taxonomy_term=' . $entity->id())
    ->countQuery()
    ->execute()
    ->fetchField();

  if ($menu_link_exists > 0) {
    $database->delete('menu_tree')
      ->condition('id', 'taxonomy_menu.menu_link%', 'LIKE')
      ->condition('route_param_key', 'taxonomy_term=' . $entity->id())
      ->execute();
    \Drupal::service('router.builder')->rebuild();
  }
}

This is a more heavy hammer approach but it seems to resolve the issue

DamienMcKenna’s picture

Assigned: millenc » Unassigned
Issue tags: +Needs tests

Let's add test coverage for this too, to make sure the functionality works as expected.