The Problem

After you have made a menu branch using the module erratic random behaviour can occur on cache flush or term saving. Most specifically the weights become normalised to 0 and the menu items then reset to alphabetical order. This is on the dev release which even sets the weight to the weight of the term.

'weight' => $term->getWeight(),

The problem eventually comes in when you load up the menu and do a transform on the items.

        $manipulators = [
            ['callable' => 'menu.default_tree_manipulators:checkAccess'],
            ['callable' => 'menu.default_tree_manipulators:generateIndexAndSort'],
        ];

        return $this->menuLinkTree->transform($tree, $manipulators);

The generateIndexAndSort then calls up the menu item weight which looks at the pluginDefinition['weight'] which is not being correctly set or saved. Thus it returns 0 and sets the pluginDefinition['weight'] also to 0 so now your menu is permanently re-ordered.

To recreate

1) Create a multi branch vocabulary
2) Add items in reverse alpha order to the vocabulary (z-a)
3) Create the taxonomy in the menu using the module.
4) In a menu factory service call up the menu and transform it using "generateIndexAndSort"

Then play

- Rearrange the items in the menu, then flush cache.
- Rearrange the items in the originating taxonomy flush cache.
- Do either of these and then resave the taxonomy menu entry.
- Edit a term and resave it. Flush cache.

The most noticable one is when you edit a term and resave it. This blows out the "pluginDefinition['weight']" and causes all the items in the menu then to have a default weight of 0. So when you do a "indexAndSort" on the menu items they will sort alphabetical.

Final Thoughts

I believe the problem is that the module is not making true content entity links. Instead it is making some sort of hybrid menu links and these links are subject to resets and flush cache issue.

Current Solution

At present we are instead using the "Simple Taxonomy Module" (stm). This is creating stand alone regular links in the menus that have to be ordered and resync however they do not jump or reset.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

brownrl created an issue. See original summary.

szantog’s picture

A pretty ugly workaround:

/**
 * Implements hook_cache_flush().
 */
function MYMODULE_cache_flush() {
  // Pick up a term id from the affected vocabulary.
  $term = Term::load(TERM_ID);
  \Drupal::service('taxonomy_menu.helper')->generateTaxonomyMenuEntries($term, TRUE);
}
dkre’s picture

Ran into the same issue. Drupal 8.3.7 and 8.3.3

I would see the term weight reset on saving a term without a cache flush.

Here's my workaround:

function hook_entity_update(Drupal\Core\Entity\EntityInterface $entity){
  if($entity->getEntityTypeId() == 'taxonomy_term'){
    \Drupal::service('taxonomy_menu.helper')->generateTaxonomyMenuEntries($entity, TRUE);
  }
}

mirom’s picture

Issue tags: +Needs tests

I was able to reproduce this problem on current 8.x-3.x-dev release. Working on fix. Meanwhile I can confirm that before-mentioned approaches fix the issue.

mirom’s picture

mirom’s picture

Status: Active » Needs review
FileSize
418 bytes

I think that this patch works for me, worth testing. It allows plugin manager to override also parent with incoming value.

  • dstol committed 1103ad0 on 8.x-3.x authored by mirom
    Issue #2861460 by mirom: Menu Order Reset (Cache Flush, Term Save)
    
dstol’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

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

Lukas von Blarer’s picture

I had this issue again on a 8.4.x install. After updating to 8.5.x everything worked fine.

rgeerolf’s picture

I still have this problem with the latest dev and Drupal 8.5.1 so maybe it's not entirely fixed?

Lukas von Blarer’s picture

In my case this was only resolved by installing updates. Do you want to create a follow-up issue?

rgeerolf’s picture

By installing updates, you mean by updating to the latest stable from Drupal Core?

zepner’s picture

I tried the most basic use-case for this module and the issue remains in 8.x-3.x.
Configs have been locked down, but a cache refresh still wipes the menu weights rendering a mess.
Unusable, unless I'm missing something.

miiimooo’s picture

I've investigated this issue and I think it's down to (stale or old) static menu overrides. This also explains that the symptoms can vary from site to site.

The quickfix is:

UPDATE `config` SET `name` = 'RENAMED.core.menu.static_menu_link_overrides' WHERE `config`.`collection` = '' AND `config`.`name` = 'core.menu.static_menu_link_overrides';

Which removes all static menu overrides!!

After that you can do a cache rebuild and everything is still the same.

Problem solve.. not really but maybe it's a good starting help for someone else.

Could a maintainer re-open this issue?

UPDATE: Actually this was an old configuration file (a menu override..)

miiimooo’s picture

Version: 8.x-3.x-dev » 8.x-3.4
FileSize
571 bytes

Attached is a patch that makes it possible to Reset Taxonomy-menu-based menu items (see previous comment) in the menu overview page.

andrey.troeglazov’s picture

Status: Closed (fixed) » Needs review
WalkingDexter’s picture

The solution from #2 does not work for me.
I use the event subscriber.

/**
 * Re-saves the taxonomy menu entities.
 *
 * Callback for the RoutingEvents::FINISHED event.
 */
public function routeRebuildFinished() {
  if ($this->moduleHandler->moduleExists('taxonomy_menu')) {
    $storage = $this->entityTypeManager->getStorage('taxonomy_menu');

    foreach ($storage->loadMultiple() as $taxonomy_menu) {
      $taxonomy_menu->save();
    }
  }
}
sittard’s picture

Just ran into this issue. It looks like this code has been committed to the dev branch of this module (https://www.drupal.org/commitlog/commit/230/1103ad0855de4d242364a5b7e74a...) and that seems to be working better for me but we are still experiencing issues with the menu weights being reset when the cache is flushed on Drupal 8.6.x.

  • dstol committed 49baf3e on 8.x-3.x authored by miiimooo
    Issue #2861460 by mirom, miiimooo, dstol: Menu Order Reset (Cache Flush...
dstol’s picture

Status: Needs review » Fixed

Thanks for the contribution!

Status: Fixed » Closed (fixed)

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

DamienMcKenna’s picture