Rebuilding menu tree?

Created on 12 September 2023, over 1 year ago
Updated 19 September 2023, over 1 year ago

Hey all,

I've got a bit of an issue with migrating menu links from a D7 site to group content menu. I can see that the links are being created correctly with the correct name in menu_link_content_data however when viewing menu_tree, the menu names are incorrect for some reason.

In menu_tree, a number of links are showing a menu_name value of group_menu_link_content-1 whereas in menu_link_content_data the menu links are showing the correct menu name of group_menu_link_content-2 or group_menu_link_content-3, depending on where I'm migrating the content to. Not really sure what might be causing this but I'm wondering if there's a way of rebuilding the menu tree?

I can see if I truncate menu_tree that the drupal admin/user/tools etc. menu links are recreated in menu_tree but not the group menu links.

Wondered if anyone has any advice on rebuilding the group menu trees, if it's possible out of the box with group_content_menu?

Thanks in advance for any help,

🐛 Bug report
Status

Closed: works as designed

Version

3.0

Component

Code

Created by

🇬🇧United Kingdom welly

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @welly
  • Status changed to Closed: works as designed over 1 year ago
  • 🇬🇧United Kingdom welly

    It's just occurred to me why this isn't working. So I'll close this issue.

  • Status changed to Active over 1 year ago
  • 🇬🇧United Kingdom welly

    Reopening this as I'm running into a new similar/related issue. When programmatically creating menu links that will live in a different menu entirely, I keep finding that menu_tree gets updated with group_menu_link_content-1 rather than the menu name that I've specified.

    I've been creating my menu link as follows. The node is a node that belongs to a group so wonder if something is post processing the menu link creation to assign the link to a different menu? Oddly, if I look at menu_link_content, I can see the correct group has been stored in menu_name, it's just in menu_tree where it differs.

          $menu_link = \Drupal::entityTypeManager()
            ->getStorage('menu_link_content')
            ->create([
              'title' => $definition['title'],
              'description' => $definition['description'],
              'link' => [
                'uri' => 'entity:node/' . $definition['route_parameters']['node'],
              ],
              'menu_name' => $menu_name,
              'weight' => $definition['weight'],
              'enabled' => boolval($definition['enabled']) ? TRUE : FALSE,
              'expanded' => boolval($definition['expanded']) ? TRUE : FALSE,
              'parent' => $definition['id'] !== $parent_menu_link['id'] ? $parent_menu_link['id'] : NULL,
            ]);
          $menu_link->save();
    
  • Status changed to Closed: works as designed over 1 year ago
  • 🇬🇧United Kingdom welly

    Ok, closing this (again) :) It looks like it's something in MenuTreeStorage which is causing this issue and I think I've found a work around.

Production build 0.71.5 2024