30
Mar.2020
Drupal 10: Remove all menu items from the site programmatically
During a migration of the content and testing the functionality, we are playing a lot with adding/removing menu items for nodes.
Here's a snippet on how to delete all links in a menu.
// 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);
Comments