Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By magahugu2 on
Hello,
I have read the documentation on how to add a menu item. I have made a custom module. Usually I use hooks to alter antything in the site. Am I supposed to be calling this menu creation code as part of a hook?
use Drupal\menu_link_content\Entity\MenuLinkContent;
$menu_link = MenuLinkContent::create([
'title' => t('Mein Konto'),
'link' => ['uri' => 'internal:/user/' . $uid . '/edit'],
'menu_name' => 'account',
'expanded' => TRUE,
]);
$menu_link->save();
}
Cheers,
Urs