The Standard profile adds a "Home" link through its standard.links.menu.yml. When this menu item is re-ordered (the weight changes to a non 0 value) and saved gets disabled with the next clearing of caches.

I created a test to demonstrate the issue, it can be moved or merged to another test once it is more clear where it should go.

It is very easy to reproduce:

  1. Install standard.
  2. Add a menu item to the main menu (through a node or any other way, this is not even necessary)
  3. Reorder the menu items (if you do it with js you can also reorder any item, as this results assigning weights to all items)
  4. Save the reordered list.
  5. Enjoy the menu as you configured it.
  6. Clear all caches
  7. Find the Home item disabled.

The only work around is to manually set the weight of "Home" to 0 as then it survives clearing caches.

Comments

bircher created an issue. See original summary.

catch’s picture

Title: Clearing caches disables reorderd, yaml discovered menu links. » (Weight?) Overridden menu links are disabled on cache rebuild
Priority: Normal » Critical
Issue tags: +D8 upgrade path

So we're not noticing this in HEAD because people aren't developing on core by customizing menu links much.

But in actual site building, setting up your main/secondary/user menu how you want it, then those links getting disabled every cache clear is a horrible horrible issue, in a similar way to #2505989: Controllers render caching at the top level and setting a custom page title lose the title on render cache hits except it looks like this additionally involves data loss.

Tagging D8 upgrade path because this was re-discovered in #2341575: [meta] Provide a beta to beta/rc upgrade path and even if it's not the upgrade path being broken, it certainly looked like it from plach's testing - if someone hadn't already known about this issue we could have lost hours of debugging time.

The combination of customizing menu links being quite basic functionality, cache clearing being non-optional and data loss makes this critical I think.

tim.plunkett’s picture

Status: Active » Needs review

Let's see if the test fails.

dawehner’s picture

Yeah its a pretty damn problem, on the other hand I have seen sites where things actually work, they also had a working update path, so this seems to be a edge case triggered by something. I guess the overridden part is the key indeed. Will have a look at that tomorrow morning

Status: Needs review » Needs work

The last submitted patch, menu-link-reorder-TEST-ONLY.patch, failed testing.

larowlan’s picture

Assigned: Unassigned » larowlan

taking a look

webchick’s picture

Issue tags: +beta target

Tentatively tagging beta target, since I believe it blocks the closing of #2341575: [meta] Provide a beta to beta/rc upgrade path.

catch’s picture

I'm on the fence about that. On the one hand it's not actually an upgrade path issue. On the other, it's impossible to distinguish between this and an upgrade gone wrong, and represents data loss on new sites as well as ones upgrading from betas. So it probably should be yes.

larowlan’s picture

Assigned: larowlan » Unassigned
Status: Needs work » Needs review
StatusFileSize
new719 bytes
new3.27 KB

So the issue is the \Drupal\Core\Menu\MenuLinkDefault::updateLink passes on only the changed keys and the menu name.

e.g.

array(
  'weight' => -10,
  'menu_name => 'main,
);

and then in \Drupal\Core\Menu\StaticMenuLinkOverrides::saveOverride we do this

$expected = array(
      'menu_name' => '',
      'parent' => '',
      'weight' => 0,
      'expanded' => FALSE,
      'enabled' => FALSE,
    );
    // Filter the overrides to only those that are expected.
    $definition = array_intersect_key($definition, $expected);
    // Ensure all values are set.
    $definition = $definition + $expected;

So 'enabled' FALSE, 'expanded' FALSE, 'parent' '' all get added to the stored values.

Let's see what else breaks

larowlan’s picture

Title: (Weight?) Overridden menu links are disabled on cache rebuild » Overridden menu links lose parent, expanded and enabled (are disabled) status on cache clear

New title, as its not just status

jibran’s picture

Status: Needs review » Reviewed & tested by the community

This is ready.

+++ b/core/lib/Drupal/Core/Menu/MenuLinkDefault.php
@@ -96,7 +96,7 @@ public function updateLink(array $new_definition_values, $persist) {
-      $this->staticOverride->saveOverride($this->getPluginId(), $overrides);
+      $this->staticOverride->saveOverride($this->getPluginId(), $this->pluginDefinition);

Nice fix.

rootwork’s picture

Presumably this would also close #2468713: Internal/custom menu links force-reset to the top of their menus on cache rebuild -- there's a patch there too, but this one is much more recent.

Not sure if this patch pulled from that at all, but as I _have_ been developing on D8 and (clients) use custom links, I deeply appreciated the work that StryKaizer, paulmckibben and jhedstrom put into that patch, in case it seems worth adding some credit for them.

dawehner’s picture

StatusFileSize
new5.5 KB
new2.23 KB

Oh nice catch. You know, this is another classical example of a problem of using arrays ... If you look at the documentation, it clearly says what you should return.

* @return array
* The plugin definition incorporating any allowed changes.

Just checked the other implementations and they are fine.

I'm sorry but I could not resist to add a unit test

dawehner’s picture

@rootwork
If I read the other issue correctly, this is a different issue, especially see the comment of paulmckibben #2468713-33: Internal/custom menu links force-reset to the top of their menus on cache rebuild
Sadly d.o. requires people to make a comment to give them credit at the moment.

rootwork’s picture

@dawehner Interesting, OK. Well if it is a separate issue then I guess they'll get credit if/when that lands :)

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed 663848e and pushed to 8.0.x. Thanks!

  • alexpott committed 663848e on 8.0.x
    Issue #2548009 by larowlan, dawehner, bircher: Overridden menu links...

Status: Fixed » Closed (fixed)

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

dawehner’s picture