Commit bfc18185 authored by vuil's avatar vuil Committed by develCuy

Issue #3047794 by heshanlk, vuil: Cannot uninstall the module without breaking the menus

parent b716d83c
......@@ -13,5 +13,37 @@ function menu_token_uninstall() {
// Remove the styles directory and generated images.
\Drupal::service('config.factory')->getEditable('menu_token.link_configuration_storage')->delete();
\Drupal::service('config.factory')->getEditable('menu_token.availableentitiesconfiguration')->delete();
// Make sure all the custom menus are not discoverable so they do not dissaper
$connection = \Drupal::service('database');
$query = $connection->select('menu_link_content_data', 'mlcd')
->fields('mlcd', ['menu_name']);
$query->groupBy("mlcd.menu_name");
$results = $query->execute();
$menus = [];
if ($results ) {
foreach ($results as $key => $value) {
$menus[] = $value->menu_name;
}
}
// Get list of menus from menu tree where the discover is 1
$query = $connection->select('menu_tree', 'mr')
->fields('mr', ['mlid']);
$query->condition('mr.menu_name', $menus, 'IN');
$query->condition('mr.discovered', 1, '=');
$results = $query->execute();
$menu_links = [];
if ($results) {
foreach ($results as $key => $value) {
$menu_links[] = $value->mlid;
}
}
if ($menu_links) {
$num_updated = $connection->update('menu_tree')
->fields([
'discovered' => 0,
])
->condition('mlid', $menu_links, 'IN')
->execute();
\Drupal::messenger()->addStatus(t('Reset %num_updated menu items.', ['%num_updated' => $num_updated]));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment