By editor, 28 November, 2015 Question How to programmatically create and translate menu links ? Programmatically create and translate menu links. Example: use Drupal\menu_link_content\Entity\MenuLinkContent; $menu_item = MenuLinkContent::create([ 'bundle' => 'menu_link_content', 'langcode' => 'en', 'title' => 'My menu link', 'description' => 'My description.', 'menu_name' => 'main', 'link' => [['uri' => 'internal:/taxonomy/term/15']], 'parent' => 'menu_link_content:c8859c9c-a550-45a9-a705-5d032dee525c', 'weight' => 0, ]); $menu_item->save(); $menu_item_es = $menu_item->addTranslation('es'); $menu_item_es->title = 'Mi enlace del menú'; $menu_item_es->description = 'Mi descripción.'; $menu_item_es->save(); Tags Drupal 8 Code Comments You must have JavaScript enabled to use this form. Your name Subject Comment About text formats Plain text No HTML tags allowed. Lines and paragraphs break automatically. Web page addresses and email addresses turn into links automatically.
Comments