// Need to replace 'sidebar-menu' menu name value with own name.
$mids = \Drupal::entityQuery('menu_link_content')
->condition('menu_name', 'sidebar-menu')
->execute();
$controller = \Drupal::entityTypeManager()->getStorage('menu_link_content');
$entities = $controller->loadMultiple($mids);
$controller->delete($entities);
For delete all the links in a particular menu like footer
$old_menu_links = \Drupal::entityTypeManager()->getStorage('menu_link_content')
->loadByProperties(['menu_name' => 'footer']);
foreach ($old_menu_links as $old_menu_link) {
$old_menu_link->delete();
}
For update to existing menu
$menu_links = \Drupal::entityTypeManager()->getStorage('menu_link_content')
->loadByProperties(['menu_name' => 'footer']);
foreach ($menu_links as $menu_link) {
if ($menu_link->gettitle() == 'old-title') {
$menu_link->set('title', 'new-title');
$menu_link->save();
}
}
No comments:
Post a Comment