How to map the menu_link field to an already existing menu item?

Created on 3 October 2024, 3 months ago

We are migrating a monolithic menu to group_content_menu. Group content entities have a menu_link field on them. They were originally pointing to menu items in the monolothic menu, they now need to point to the migrated group_content_menu menu_link items.

I'm trying to set the menu link fields on any group content entity to the first menu link field in their group_content_menu that matches the group content entity route, but it is instead creating duplicate links.

This is roughly what i am up to:

// @todo This code is causing double menu items!
                $menu_item_values = [
                  'title' => $menu_tree_item->link->getTitle(),
                  'description' => $menu_tree_item->link->getDescription(),
                  'parent' => $menu_tree_item->link->getParent(),
                  'menu_name' => $menu_tree_item->link->getMenuName(),
                  'weight' => $menu_tree_item->link->getWeight(),
                ];
                $group_content->set(group_content_submenu_group_content_menu_field(), $menu_item_values);
                $group_content->save();
πŸ’¬ Support request
Status

Active

Version

2.0

Component

Documentation

Created by

πŸ‡ΊπŸ‡ΈUnited States jnicola

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

Comments & Activities

Production build 0.71.5 2024