Deletes multiple menu links.
array $mlids: An array of menu link IDs.
bool $force: (optional) Forces deletion. Internal use only, setting to TRUE is discouraged. Defaults to FALSE.
bool $prevent_reparenting: (optional) Disables the re-parenting logic from the deletion process. Defaults to FALSE.
function menu_link_delete_multiple(array $mlids, $force = FALSE, $prevent_reparenting = FALSE) {
if (!$mlids) {
// If no IDs or invalid IDs were passed, do nothing.
return;
}
$controller = Drupal::entityManager()
->getStorageController('menu_link');
if (!$force) {
$entity_query = Drupal::entityQuery('menu_link');
$group = $entity_query
->orConditionGroup()
->condition('module', 'system', '<>')
->condition('updated', 0, '<>');
$entity_query
->condition('mlid', $mlids, 'IN');
$entity_query
->condition($group);
$result = $entity_query
->execute();
$entities = $controller
->load($result);
}
else {
$entities = $controller
->load($mlids);
}
$controller
->preventReparenting($prevent_reparenting);
$controller
->delete($entities);
}