I created Menu Link Content entities and saved them in a menu.
$menu_link = MenuLinkContent::create([
'title' => 'Menu item',
'bundle' => 'menu_link_content',
'link' => [['uri' => 'internal:/']],
'menu_name' => 'testing',
])->save();
$menu_link_2 = MenuLinkContent::create([
'title' => 'Menu item',
'bundle' => 'menu_link_content',
'link' => [['uri' => 'internal:/']],
'menu_name' => 'testing',
])->save();
How can I rearrange $menu_link_2
to be a child of $menu_link
?
Looking at menu_ui
, they seem to update Menu Link Content in a given order, and then rebuild the menu tree; finally, the Menu entity is saved.
$menu_link_manager = \Drupal::service('plugin.manager.menu.link');
$menu_link_manager->updateDefinition($menu_link_2->getPluginId(), [
'parent' => $menu_link->getPluginId(),
]);
How can I rebuild the menu tree and save the menu?
Why? I'm writing a Kernel test for a module that fires when the menu link content has been saved AND then when the Menu itself has been saved.